Android image merging,

Source: Internet
Author: User

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:

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.