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.