Methods of passing pictures (Bitmap) between Android activity _android

Source: Internet
Author: User

In Android development, passing parameters between events is common; if we want to pass pictures between the activity;
1. The mainactivity includes a imageview; When we click on the ImageView, we pass the picture to another activity.
Main code for Mainactivity:

Copy Code code as follows:

Intent intent=new Intent (mainactivity.this,tranactivity.class);
Intent.putextra ("Bitmap", bitmap);
StartActivity (Intent);

Biitmap is the Image Object Bitmap=bitmapfactory.decoderesource (Getresources (), R.drawable.ic_launcher) obtained in the OnCreate method;
When we click on the picture, we jump to tranactivity and pass a bitmap as a parameter
2. In the Tranactivity receive mainactivity pass over the bitmap;
Copy Code code as follows:

imageview= (ImageView) Findviewbyid (R.id.trans_imageview);
Intent intent=getintent ();
if (intent!=null)
{
Bitmap=intent.getparcelableextra ("Bitmap");
Imageview.setimagebitmap (bitmap);
}

Get bitmap in tranactivity and give imageview to display pictures
3. By accepting the picture, you can enlarge the picture
Copy Code code as follows:

ImageView = (ImageView) Findviewbyid (R.id.trans_imageview);
Intent Intent = Getintent ();
if (intent!= null) {
Bitmap = Intent.getparcelableextra ("bitmap");
Matrix matrix = new Matrix (); Enlarge 1.5 times times after receiving picture
Matrix.postscale (1.5f, 1.5f);
Bitmap bit = Bitmap.createbitmap (Bitmap, 0, 0, bitmap.getwidth (),
Bitmap.getheight (), Matrix, True);
Imageview.setimagebitmap (bit);
}

Run effect

tranactivity; effect after amplification

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.