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