Today we learn to tear clothes. Let me first say the principle of tearing clothes: tear clothes There are 2 pictures, a beautiful woman wearing a picture of the coat, a beautiful woman wearing underwear pictures. When we swipe the finger, and then set the picture of the beautiful woman in the coat of clothing to a transparent color, so the following picture is displayed.
Directly on the code:
public class Mainactivity extends Activity {private Bitmap bmpcopy;private Paint paint;private Canvas canvas;private Image View ImageView; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate) ; Setcontentview (R.layout.activity_main); 1: Because I modify the coat of the picture, so to give the coat to set a copy Bitmap bmpsrc = Bitmapfactory.decoderesource (Getresources (), R.drawable.awaiyi); Bmpcopy = Bitmap.createbitmap (Bmpsrc.getwidth (), Bmpsrc.getheight (), Bmpsrc.getconfig ()); Paint = new paint (); Canvas = new canvas (bmpcopy); Canvas.drawbitmap (BMPSRC, New Matrix (), paint); ImageView = (ImageView) Findviewbyid (R.ID.LV2); Imageview.setimagebitmap (bmpcopy); 2: Monitor Touch event Imageview.setontouchlistener (new Ontouchlistener () {@Overridepublic Boolean onTouch (View V, motionevent Event) {//We only care about Sliding event switch (event.getaction ()) {Case motionevent.action_move://finger slide track set to transparent color int x = (int) EVent.getx (); int y = (int) event.gety (); Cleanimage (x, y); break;default:break;} return true;}}); }//because only 1 pixels are set at a time, this is very slow public void cleanimage (int x, int y) {for (int i = -10; i <; i++) {for (int j = -10; J <; J + +) { Draw a round if (math.sqrt (I*i + j*j) <= 10) with X, y as the center radius of 10 {//To determine if the finger is out of bounds if the bounds are not handled if (X+i < Bmpcopy.getwidth () && y+j < Bmpcopy.getheight () && x+i >=0 && y+j >=0) {//Set Transparent Color Bmpcopy.setpixel (x+i, Y+j, color.transparent);//Set Image Imageview.setimagebitmap (bmpcopy);}}}}
:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Multimedia development Learning RIP clothes