Android Study Notes: Advanced 16 bitmapshader

Source: Internet
Author: User

<1> Introduction

For details, refer to the blog post: Android learning notes. Advanced 15: shader rendering.

 

PublicBitmapshader(Bitmap bitmap, shader. tilemode tilex, shader. tilemode tiley)

Call this method to generate a Renderer with a bitmap ).

Bitmap bitmap used in the Renderer

Tilex the tiling mode for X to draw the bitmap in. tile mode in the X direction on the in-place Graph

Tiley the tiling mode for y to draw the bitmap in. tile mode in the Y direction on the in-place Graph

 

Tilemode: (there are three types)

Clamp: If the Renderer is out of the original boundary range, the inner edge of the replication range is colored.

Repeat: Specifies the horizontal and vertical repeated Renderer image, tiled.

Mirror: Repeated horizontal and vertical Renderer Images, AndRepeatThe repeat method is different. The image is tiled.

Still not quite clear? Let's take a look!

RepeatMirror

<2> Implementation

 

Package xiaosi. bitmapshader; </P> <p> Import android. app. activity; <br/> Import android. OS. bundle; </P> <p> public class bitmapshaderactivity extends activity {<br/>/** called when the activity is first created. */<br/> private bitmapshaders = NULL; <br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); </P> <p> bitmapshaders = new bitmapshaders (this); <br/> setcontentview (bitmapshaders); <br/>}< br/>}

 

Bitmapshaders. Java

Package xiaosi. bitmapshader; </P> <p> Import android. content. context; <br/> Import android. graphics. bitmap; <br/> Import android. graphics. bitmapshader; <br/> Import android. graphics. canvas; <br/> Import android. graphics. paint; <br/> Import android. graphics. shader; <br/> Import android. graphics. drawable. bitmapdrawable; <br/> Import android. graphics. drawable. shapedrawable; <br/> Import android. graphics. drawable. shapes. ovalshape; <br/> Import android. view. view; </P> <p> public class bitmapshaders extends view <br/>{< br/> private bitmapshader = NULL; <br/> private Bitmap bitmap = NULL; <br/> private paint = NULL; <br/> private shapedrawable = NULL; <br/> private int bitmapwidth = 0; <br/> private int bitmapheight = 0; <br/> Public bitmapshaders (context) <br/>{< br/> super (context ); <br/> // obtain the image <br/> bitmap = (bitmapdrawable) getresources (). getdrawable (R. drawable. h )). getbitmap (); <br/> bitmapwidth = bitmap. getwidth (); <br/> bitmapheight = bitmap. getheight (); <br/> // construct the Renderer bitmapshader <br/> bitmapshader = new bitmapshader (bitmap, shader. tilemode. mirror, shader. tilemode. repeat); <br/>}< br/> @ override <br/> protected void ondraw (canvas) <br/>{< br/> super. ondraw (canvas ); <br/> // crop the image to an elliptical shape <br/> // create a shapedrawable object and define the shape as an elliptical shape <br/> shapedrawable = new shapedrawable (New ovalshape ()); <br/> // get the paint brush and set the Renderer <br/> shapedrawable. getpaint (). setshader (bitmapshader); <br/> // set the display area <br/> shapedrawable. setbounds (20, 20, BitmapWidth-60, BitmapHeight-60); <br/> // draw shapedrawable <br/> shapedrawable. draw (canvas); <br/>}< br/>

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.