The effect of a rounded picture is achieved when you do the project today, like this:
after searching online for information, learn about Android Porterduff and Xfermode,
1. XfermodeYou can modify the Xfermode of the paint to affect how new colors are drawn above the canvas's existing image. Under normal circumstances, drawing on an existing image will add a new layer of shape on top of it. If the new paint is completely opaque, it will completely cover the paint below, and if it is partially transparent, it will be stained with the following color.
the following subclass of Xfermode can change this behavior:Avoidxfermode Specifies a color and tolerance, forcing paint to avoid drawing on it (or just drawing on it).
Pixelxorxfermode A simple pixel XOR operation (XOR) is applied when the existing color is overwritten.
Porterduffxfermode This is a very powerful conversion mode, using it, you can use any of the 16 porter-duff rules of the image composition to control how paint interacts with existing canvas images.
first look at (from Apidemos/graphics/xfermodes):
From the above we can see that Porterduff.mode is an enumeration class with a total of 16 enumeration values:
1.porterduff.mode.clear
The drawing is not submitted to the canvas.
2.porterduff.mode.src
Show Top Draw picture
3.porterduff.mode.dst
Show Lower drawing pictures
4.porterduff.mode.src_over
Normal drawing shows that the upper and lower layers are drawn with overlapping covers.
5.porterduff.mode.dst_over
The upper and lower layers are displayed. The lower level is shown on the home.
6.porterduff.mode.src_in
Draw the intersection of two layers. Displays the upper layer.
7.porterduff.mode.dst_in
Draw the intersection of two layers. Displays the lower layer.
8.porterduff.mode.src_out
Draw the non-intersecting portion of the upper layer.
9.porterduff.mode.dst_out
Remove the layer to draw the non-intersecting part.
10.porterduff.mode.src_atop
Remove the non-intersecting part of the layer from the upper intersection section
11.porterduff.mode.dst_atop
Take the upper non-intersecting part and the lower part of the intersection
12.porterduff.mode.xor
XOR: Remove the two Layer intersection section
13.porterduff.mode.darken
Take two layers of all areas, the intersection part of the color deepened
14.porterduff.mode.lighten
Take two layers all, light the intersection part color
15.porterduff.mode.multiply
Take two layer intersection part overlay color
16.porterduff.mode.screen
Take two layers of all areas, the intersection part becomes transparent color
The following methods can achieve the effect of Figure 1:
<span style= "font-size:18px;" ><span style= "White-space:pre" ></span>/** * Get rounded bitmap method * * @param bitmap * Bitmap required to convert to rounded corners * @param p Ixels * Rounded degrees, the larger the value, the larger the fillet * @return processed rounded bitmap */public static Bitmap Toroundcorner (Bitmap Bitmap, int pixels) {Bit Map output = Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), config.argb_8888); Canvas canvas = new canvas (output), final int color = 0xff424242;final Paint paint = new paint (); final rect rect = new rect (0, 0, bitmap.getwidth (), Bitmap.getheight ()), final RECTF RECTF = new RECTF (rect); final float roundpx = Pixels;paint.setan Tialias (True); Canvas.drawargb (0, 0, 0, 0);p aint.setcolor (color); Canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint) ;//Draw the intersection of two layers to show the upper layer. Paint.setxfermode (New Porterduffxfermode (mode.src_in)); Canvas.drawbitmap (bitmap, rect, rect, paint); return output;} </span><span style= "FONT-SIZE:14PX;" ></span>
Demo See address:
http://download.csdn.net/detail/u013807286/9001405
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Fillet Picture Implementation