Tear clothes for Android multimedia development and learning

Source: Internet
Author: User
Tags transparent color

Tear clothes for Android multimedia development and learning

Today we are learning to tear clothes. Let me first talk about the principle of tearing clothes: There are two pictures of tearing clothes, one is a picture of a beautiful woman wearing a coat, and the other is a picture of a beautiful woman wearing a lingerie. When our fingers slide, we set the pictures of beautiful women in the coat to transparent color, so that the following picture is displayed.


Directly run the Code:


Public class MainActivity extends Activity {private Bitmap BMP copy; private Paint paint; private Canvas canvas; private ImageView imageView; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); // 1: Because I modify the coat image, set the copy Bitmap BMP = BitmapFactory for the coat. decodeResource (getResources (), R. drawable. awaiyi); BMP copy = Bitmap. createBitmap (bmp src. getWidth (), bmp src. getHeight (), bmp src. getConfig (); paint = new Paint (); canvas = new Canvas (BMP copy); canvas. drawBitmap (bmp src, new Matrix (), paint); imageView = (ImageView) findViewById (R. id. lv2); imageView. setImageBitmap (BMP copy); // 2: listens to the imageView of the touch event. setOnTouchListener (new OnTouchListener () {@ Overridepublic boolean onTouch (View v, MotionEvent event) {// We only care about the sliding event switch (event. getAction () {case MotionEvent. ACTION_MOVE: // the trajectory of finger sliding is set to transparent int x = (int) event. getX (); int y = (int) event. getY (); cleanImage (x, y); break; default: break;} return true ;}}) ;}// because only one pixel is set at a time, public void cleanImage (int x, int y) {for (int I =-10; I <10; I ++) {for (int j =-10; j <10; j ++) {// draw if (Math. sqrt (I * I + j * j) <= 10) {// determines whether the finger has crossed the border. if the cross border is not processed, if (x + I <BMP copy. getWidth () & y + j <BMP copy. getHeight () & x + I> = 0 & y + j> = 0) {// you can specify a transparent BMP copy. setPixel (x + I, y + j, Color. TRANSPARENT); // sets the image imageView. setImageBitmap (BMP copy );}}}}}}





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.