I have to transfer the image from one activity to another. In first activity there are two buttons (take photo) and (View Image).User can take photo by pressing (take photo) button and that photo will be transfer to another activity class which can be view by (View Image) button. Help required.
Asked
Active
Viewed 642 times
-5
-
Is this image in resouces? If so, then pass only its id. If you download this image, can't you download it in another activity? – miljon Feb 28 '17 at 11:50
-
Just pass the path of the image file. And reload it in the new Activity. – Phantômaxx Feb 28 '17 at 12:03
-
@Mij I want to capture picture in first activity and pass that picture in second activity to display that image – Furqan Ahmad Feb 28 '17 at 14:14
1 Answers
1
There is another way for doing this. You can convert the Bitmap image and convert into Base 64 and store it in shared preference. In another activity you can reconvert back it into bitmap and use where ever you want.
Bitmap Conversion and Storing into Shared Preference
Bitmap photo = (Bitmap) intent.getParcelableExtra("Your data");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
String temp = Base64.encodeToString(b, Base64.DEFAULT);
myPrefsEdit.putString("url", temp);
myPrefsEdit.commit();
Retrieving from Shared Preference and Loading it into an ImageView
String temp = myPrefs.getString("url", "defaultString");
try {
byte[] encodeByte = Base64.decode(temp, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
picture.setImageBitmap(bitmap);
} catch (Exception e) {
e.getMessage();
}

Vishnu M Menon
- 1,459
- 2
- 19
- 34