Android image merging,
This article combines Android clips.
The layout design is relatively simple:
<RelativeLayout xmlns: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" > <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" /></RelativeLayout>
The logic code is as follows:
Public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); ImageView iv = (ImageView) findViewById (R. id. iv); // image synthesis-canvas first draws A and then draws B Bitmap bitmap = BitmapFactory. decodeResource (getResources (), R. drawable. test); // bitmap is read-only Bitmap alterBitmap = Bitmap. createBitmap (bitmap. getWidth (), bitmap. getHeight (), bitmap. getConfig (); Canvas canvas = new Canvas (alterBitmap); Paint paint = new Paint (); paint. setColor (Color. BLACK); canvas. drawBitmap (bitmap, new Matrix (), paint); Bitmap ic_luncher = BitmapFactory. decodeResource (getResources (), R. drawable. ic_launcher); canvas. drawBitmap (ic_luncher, new Matrix (), paint); iv. setImageBitmap (alterBitmap );}}
The final effect is as follows:
Open the API Demo icon of the android phone
Select Graphics and then Xfermodes, as shown below:
Various image merging modes are shown here, which can be implemented in the Code. The DARKEN mode is used here, and the code is as follows:
Public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); ImageView iv = (ImageView) findViewById (R. id. iv); // image synthesis-canvas first draws A and then draws B Bitmap bitmap = BitmapFactory. decodeResource (getResources (), R. drawable. test); // bitmap is read-only Bitmap alterBitmap = Bitmap. createBitmap (bitmap. getWidth (), bitmap. getHeight (), bitmap. getConfig (); Canvas canvas = new Canvas (alterBitmap); Paint paint = new Paint (); paint. setColor (Color. BLACK); paint. setXfermode (new porterduxfermode (PorterDuff. mode. DARKEN); canvas. drawBitmap (bitmap, new Matrix (), paint); Bitmap ic_luncher = BitmapFactory. decodeResource (getResources (), R. drawable. ic_launcher); canvas. drawBitmap (ic_luncher, new Matrix (), paint); iv. setImageBitmap (alterBitmap );}}
The effect is as follows: