0

I have two activity, First with button, which calls void openCamera, and second, where I need to get bitmap.
I have two questions:
1. Which line of code is saving pictures?
2. How I can take a bitmap from OnActivityResult and get it in another activity?

private void openCamera() {
        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "Taking pic from the Camera");
        image_uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, image_uri);
        startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        SelectedImage.setImageURI(image_uri);
        try {
            Bitmap ImageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), image_uri);
            detectImage(ImageBitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
Leon
  • 57
  • 5

2 Answers2

1

Don't think about passing it through Bundle (docs: https://developer.android.com/guide/topics/resources/runtime-changes.html#RetainingAnObject)

I think, you should save the image in internal storage of your app and then load it in your second activity. Here are the answers explaining how to do that: Saving and Reading Bitmaps/Images from Internal memory in Android

Patryk Kubiak
  • 1,679
  • 2
  • 11
  • 17
0

Pass image uri as string along with activity intent

mIntent.putExtra("image", image_url.toString());

In the receiving activity get the uri and move your code to generate bitmap there.

String image_url = getIntent().getStringExtra("image");
//your code to get bitmap
karan
  • 8,637
  • 3
  • 41
  • 78