Principle: The two different effects of the picture in the same position, change the transparency of the image above, it can be achieved.
Layout file:
<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Android:paddingbottom= "@dimen/activity_vertical_margin"Tools:context=". Mainactivity "> <ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centerinparent= "true"Android:id= "@+id/iv_bottom" /> <ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centerinparent= "true"Android:id= "@+id/iv_top" /></Relativelayout>
Mainactivity
Packagecn.seanlou.stripclothes;Importandroid.app.Activity;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Color;ImportAndroid.os.Bundle;ImportAndroid.util.Log;Importandroid.view.MotionEvent;ImportAndroid.view.View;ImportAndroid.widget.ImageView; Public classMainactivityextendsActivity {PrivateImageView Ivbottom; PrivateImageView Ivtop; PrivateBitmap Imgblank; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Findview (); Init (); } /*** Initialize the contents of the control*/ Private voidinit () {bitmapfactory.options Options=Newbitmapfactory.options (); Options.insamplesize= 1; //gets the picture that is displayed in the image above, the Bitmapfactory.decoderesource () method gets the image encoded in RGB format and needs to be converted to ARGB format. Bitmap Imgtop =Bitmapfactory.decoderesource (Getresources (), r.mipmap.g1_up, options); //gets the picture shown in the following. Bitmap Imgbottom =Bitmapfactory.decoderesource (Getresources (), r.mipmap.g1_back, options); //Create a blank bitmap picture that shows the imgtop size of the picture above, the picture formatted in ARGB format. Imgblank =Bitmap.createbitmap (Imgtop.getwidth (), Imgtop.getheight (), Bitmap.Config.ARGB_4444); //Create the Imgblank as a canvas. Canvas Canvas =NewCanvas (Imgblank); //Paint the Imgtop on the canvasCanvas.drawbitmap (imgtop, 0, 0,NULL); Ivtop.setimagebitmap (Imgblank); Ivbottom.setimagebitmap (Imgbottom); Ivtop.setontouchlistener (NewMyontouchlistener ()); } Private voidFindview () {ivtop=(ImageView) Findviewbyid (r.id.iv_top); Ivbottom=(ImageView) Findviewbyid (R.id.iv_bottom); } Private classMyontouchlistenerImplementsView.ontouchlistener {@Override Public BooleanOnTouch (View V, motionevent event) {if(event.getaction () = =motionevent.action_move) { intx = (int) Event.getx (); inty = (int) event.gety (); LOG.I ("Location", "Current position x:" + x + ", Y:" +y); for(inti = x-20; I < x + 20; i++) { for(intj = y-20; J < Y + 20; J + +) { //dealing with picture boundary problems if(I >= 0 && i < imgblank.getwidth () && J >= 0 && J <imgblank.getheight ()) { //set the current point to transparentImgblank.setpixel (i, J, color.transparent); } } } //Show PicturesIvtop.setimagebitmap (Imgblank); } return true; } }}
Processing of bitmap picture transparency in Android (take the example of tearing beautiful clothes)