Look directly at the code, explain. The main use of image processing
PorterDuff.Mode.SRC_ATOPSRC_ATOP
Blend the source and target pixels to center the top of the image to add frame effect
Package Com.ferris.launchericonutils;import Android.app.activity;import Android.graphics.bitmap;import Android.graphics.bitmapfactory;import Android.graphics.canvas;import Android.graphics.paint;import Android.graphics.porterduff;import Android.graphics.porterduffxfermode;import Android.graphics.Rect;import Android.os.bundle;import Android.widget.imageview;public class Mainactivity extends Activity {private ImageView ImageView; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); ImageView = (ImageView) Findviewbyid (R.ID.IMAGEVIEW1);// Get the picture set in ImageView bitmap lay1 = Bitmapfactory.decoderesource (Getresources (), r.drawable.icon_folder); Bitmap lay2 = Bitmapfactory.decoderesource (Getresources (), r.drawable.mobileqq);//Get the width of the picture and create the result bitmapint width = Lay1.getwidth (); Bitmap resultbmp = Bitmap.createbitmap (width, width,bitmap.config.argb_8888); Paint paint = new paint (); Canvas canvas = new canvas (resultbmp); canvas.drAwbitmap (lay1, 0, 0, paint);//Draw the lower layer//Let the upper icon center Display int top = 0;if (Lay1.getheight () > Lay2.getheight ()) {top = (Lay1.gethei Ght ()-lay2.getheight ())/2;} else{//here can determine whether the picture is larger than the box, and then continue to get more than how much, the upper picture of the scaling, and then the intersection, the method does not write}int left = 0;if (Lay1.getwidth () > Lay2.getwidth ()) { left = (Lay1.getwidth ()-lay2.getwidth ())/2;} else{//here can determine whether the picture is larger than the box, and then continue to get greater than the number of images, the upper level of scaling, and then the intersection, the method does not write the}paint.setxfermode (new Porterduffxfermode ( PorterDuff.Mode.SRC_ATOP));//select intersection to the upper picture Canvas.drawbitmap (Lay2, left, top, paint); Imageview.setimagebitmap ( resultbmp);}}
Android Launcher icon plus frame optimization display effect