Compositing of Android Images

Source: Internet
Author: User

This article implements the synthesis of Android tablets

Layout design is relatively simple:

<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:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context=". Mainactivity " >    <ImageViewAndroid:id= "@+id/iv"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"        /></Relativelayout>

The logic section code is as follows:

 Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); ImageView IV=(ImageView) Findviewbyid (R.ID.IV); //picture Synthesis-canvas first to draw a and then to draw BBitmap Bitmap =Bitmapfactory.decoderesource (Getresources (), r.drawable.test);//Bitmap is read-onlyBitmap Alterbitmap=Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), Bitmap.getconfig ()); Canvas Canvas=NewCanvas (ALTERBITMAP); Paint Paint=NewPaint ();        Paint.setcolor (Color.Black); Canvas.drawbitmap (Bitmap,NewMatrix (), paint); Bitmap Ic_luncher=Bitmapfactory.decoderesource (Getresources (), r.drawable.ic_launcher); Canvas.drawbitmap (Ic_luncher,NewMatrix (), paint);    Iv.setimagebitmap (ALTERBITMAP); }}

The final results are as follows:

Open the Android Phone API demo icon

Select the graphics, then select Xfermodes, as follows:

This shows a variety of image synthesis patterns, which we can implement in the code, where the darken mode is used, the code is as follows:

 Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); ImageView IV=(ImageView) Findviewbyid (R.ID.IV); //picture Synthesis-canvas first to draw a and then to draw BBitmap Bitmap =Bitmapfactory.decoderesource (Getresources (), r.drawable.test);//Bitmap is read-onlyBitmap Alterbitmap=Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), Bitmap.getconfig ()); Canvas Canvas=NewCanvas (ALTERBITMAP); Paint Paint=NewPaint ();       Paint.setcolor (Color.Black); Paint.setxfermode ( New Porterduffxfermode (PorterDuff.Mode.DARKEN)); Canvas.drawbitmap (Bitmap,NewMatrix (), paint); Bitmap Ic_luncher=Bitmapfactory.decoderesource (Getresources (), r.drawable.ic_launcher); Canvas.drawbitmap (Ic_luncher,NewMatrix (), paint);    Iv.setimagebitmap (ALTERBITMAP); }}

The effect is as follows:

Compositing of Android Images

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.