Android Development Graphics processing Create a copy of a graphic

Source: Internet
Author: User

Define a layout file
<linearlayout 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:orientation= "vertical"    tools:context= ". Mainactivity ">    <button        android:layout_width=" wrap_content "        android:layout_height=" Wrap_ Content "        android:onclick=" copy "        android:text=" creates a graphics copy "/>       <imageview         android:id=" @+id/ Iv1 "        android:layout_width=" wrap_content "        android:layout_height=" wrap_content "/>            < ImageView         android:id= "@+id/iv2"        android:layout_width= "wrap_content"        android:layout_height= "wrap _content "  />            </LinearLayout>

Implementing Logic in Mainactivity
Package Com.wzw.imagecopy;import Android.app.activity;import Android.graphics.bitmap;import Android.graphics.bitmapfactory;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.matrix;import Android.graphics.paint;import Android.os.bundle;import Android.support.v4.widget.slidingpanelayout.panelslidelistener;import Android.view.view;import Android.widget.imageview;public class Mainactivity extends Activity {private ImageView imageview1;private ImageView Imageview2;private Bitmap srcbm;private Bitmap copybm; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); imageview1= (ImageView) findViewById ( R.ID.IV1); imageview2= (ImageView) Findviewbyid (R.ID.IV2); Srcbm=bitmapfactory.decoderesource (Getresources (), R.drawable.ic_launcher); Imageview1.setimagebitmap (SRCBM);//Create a copy of the original, you can modify the picture Copybm=bitmap.createbitmap ( Srcbm.getwidth (), Srcbm.getheight (), Srcbm.getconfig ());} /** * Create a copy of the original image * @paRam v */public void copy (View v) {//Prepare an artboard canvas canvas=new canvas (COPYBM);//Prepare Brush Paint paint=new paint ();p aint.setcolor ( Color.Black);//3. Start Drawing matrix m=new matrix ();//According to 1:1 draw Canvas.drawbitmap (SRCBM, M, paint);// Painting Imageview2.setimagebitmap (COPYBM);}}


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.