Android Launcher icon plus frame optimization display effect

Source: Internet
Author: User

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

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.