-5

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.

1 Answers1

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