Create a copy of the image for Android Development

Source: Internet
Author: User

Create a copy of the image for Android Development
Define a layout File

     
         
              
              
 

Implement 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 source image. You can modify the image copyBm = Bitmap. createBitmap (srcBm. getWidth (), srcBm. getHeight (), srcBm. getConfig ();}/*** create a copy of the source image * @ param v */public void copy (View v) {// prepare a Canvas canvas Canvas = new Canvas (copyBm); // prepare the Paint brush paint = new Paint (); paint. setColor (Color. BLACK); // 3. start to draw Matrix m = new Matrix (); // draw the canvas according. drawBitmap (srcBm, m, paint); // draw an image like the source image 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.