Saving Camera Bitmap to Storage, and Setting Image with Bitmap

我的梦境 提交于 2020-01-03 04:32:09

问题


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.


回答1:


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



回答2:


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().



来源:https://stackoverflow.com/questions/15373183/bitmap-not-setting-to-imageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!