Android multimedia development and learning-creating image copies

Source: Internet
Author: User

Android multimedia development and learning-creating image copies

What is creating a copy of an image? Because the image we retrieve directly from BitmapFactory is readable and cannot be modified. Assume that the user wants to modify the image. Generally, the user first creates an image of the same size as the original image in the memory based on the original image, and then modifies the image above. The user feels that the image is modified on the original image.

 

 

Public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); // 1: obtain the original image first. note: The image we get is read-only and cannot be written. to modify the image, you must create the copy Bitmap bmsRc = BitmapFactory of the image. decodeResource (getResources (), R. drawable. abc); // 2: Create a copy of The image. You can create a bitmap, bmCopy = Bitmap, in the same size as the source image in the memory. createBitmap (bmsRc. getWidth (), bmsRc. getHeight (), bmsRc. getConfig (); // 2.1 create a Paint brush paint = new Paint (); // 2.2 create a Canvas object canvas Canvas = new Canvas (bmCopy ); // draw the same canvas as the source image at 2.3. drawBitmap (bmsRc, new Matrix (), paint); // draw a straight line on the image, representing that the copy of the image is a canvas that can be modified. drawLine (30, 30,400,400, paint); ImageView iv_src = (ImageView) findViewById (R. id. lv1); ImageView iv_copy = (ImageView) findViewById (R. id. lv2); // display iv_src.setImageBitmap (bmsRc); iv_copy.setImageBitmap (bmCopy );}}
In fact, it is very easy to create a copy of the image, just as described in the Code above.

 

As follows:

Obviously, the second image can be modified.


 

 

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.