TheLettuceMaster
TheLettuceMaster

Reputation: 15744

Saving Camera Bitmap to Storage, and Setting Image with Bitmap

I know the basics on how to take a picture and set it to ImageView.

photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);

I want to do a little more than that.

I am saving it to a folder on to an SD card. That I have done successfully with this:

// intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, CAMERA_REQUEST);

Here is my next question:

Not sure how to do this: What I'd like to do next: The next time I come to this Activity, I'd like to check if that image exists and assign it to that imageView.

Upvotes: 0

Views: 264

Answers (2)

Festus Tamakloe
Festus Tamakloe

Reputation: 11310

Last days i faced this issue in one of my applications.

I'll try here to explain a little bitte what i have done.

  1. Try to save the picture full path to a storage area or to your sharedpreferences.
  2. Next time if you call your activity then check if a picture already exists and if you can use it.
  3. Prepare in your xml layout an ImageView with visibility="gone" and if the point (2.) is true then you can change the visibility to visible and set the image in the view.
  4. If the point (2.) is false then switch to camera view (SurfaceView) in order to take a new picture

Upvotes: 1

romo
romo

Reputation: 1990

You would have to use some sort of persistent storage to reference the file to check if it exists. I would just store it as a string in a preference and read it, then check if it exists and so on. Easy enough to do from the onCreate().

Upvotes: 1

Related Questions