Android Launcher icon box-added to optimize display effect, androidlauncher

Source: Internet
Author: User

Android Launcher icon box-added to optimize display effect, androidlauncher

Read the code and explain it. Mainly used for image processing

PorterDuff. Mode. SRC_ATOPSRC_ATOP

The source pixel and target pixel are mixed to make the upper-layer graph display in the center to achieve the framed 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. porterduxfermode; 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); // obtain the image Bitmap lay1 = BitmapFactory set in imageview. decodeResource (getResources (), R. drawable. icon_folder); Bitmap lay2 = BitmapFactory. decodeResource (getResources (), R. drawable. mobileqq); // obtain the image width 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 // display int top = 0 in the center of the upper layer icon; if (lay1.getHeight ()> lay2.getHeight ()) {top = (lay1.getHeight ()-lay2.getHeight ()/2;} else {// you can determine whether the image is greater than the box, and then continue to get the value greater than the box, zooming the upper-layer image, and then performing intersection operations, the method will not write} int left = 0; if (lay1.getWidth ()> lay2.getWidth () {left = (lay1.getWidth () -lay2.getWidth ()/2;} else {// here, you can determine whether the image is greater than the box, and then continue to obtain the greater value, scale the upper-layer image, and then perform intersection, method will not be written} paint. setXfermode (new porterduxfermode (PorterDuff. mode. SRC_ATOP); // select the intersection to go to the upper-layer image canvas. drawBitmap (lay2, left, top, paint); imageView. setImageBitmap (resultBmp );}}



 


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.