-2

I have a custom camera app and I want to pass the captured photo into another activity where I can add other icons (emoticons) over it.

How can i pass the captured photo to another activity?

Mike Laren
  • 8,028
  • 17
  • 51
  • 70
Blerim Blerii
  • 223
  • 3
  • 16
  • possible duplicate of [How can I pass a Bitmap object from one activity to another](http://stackoverflow.com/questions/2459524/how-can-i-pass-a-bitmap-object-from-one-activity-to-another) – stan0 Jun 22 '15 at 05:52

1 Answers1

0

You could pass the photo's URI via an intent. Assuming you call your camera with startActivityForResult(). In your camera activity:

Intent data = new Intent();
data.putExtra(MediaStore.EXTRA_OUTPUT, imageFilename);
setResult(Activity.RESULT_OK, data);
finish();

Then in your emoticon activity:

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (data != null && data.hasExtra(MediaStore.EXTRA_OUTPUT)) {
        File imageFile = new File(data.getStringExtra(MediaStore.EXTRA_OUTPUT));

        // Bitmap here, do whatever you need
        Bitmap bitmap = readBitmapFromFile(imageFile.getName());
    }
}

public static Bitmap readBitmapFromFile(@NotNull String filename) {
    File file = new File(filename);

    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inPreferredConfig = Bitmap.Config.RGB_565;
    bmOptions.inSampleSize = 1;
    bmOptions.inPurgeable = true;

    Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), bmOptions);

    return bitmap;
}
jlhonora
  • 10,179
  • 10
  • 46
  • 70
  • Please tell me what it is "FileUtils". should i put it as an int or a string or boolean ? – Blerim Blerii Jun 22 '15 at 14:16
  • @Thanks, but the Intent what should i do with it ? at mainactivity i have an imageview as a button (capture) onClick it calls a method called TakePicture(); from CameraPreview (CameraPreview.TakePicture();) and i have put intent just below this, is it right or no ? – Blerim Blerii Jun 22 '15 at 14:25