Android Multimedia development Learning RIP clothes

Source: Internet
Author: User

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

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.