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