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?
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?
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;
}