How to save a picture to a file?

佐手、 提交于 2019-12-10 10:20:57

问题


I'm trying to use a standard Intent that will take a picture, then allow approval or retake. Then I want to save the picture into a file.

Here's the Intent I am using:

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );

startActivityForResult( intent, 22 );

The documentation says:

The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.

I don't pass extra output, I hope to get a Bitmap object in the extra field of the Intent passed into onActivityResult() (for this request). So where/how do you extract it? Intent has a getExtras(), but that returns a Bundle, and Bundle wants a key string to give you something back.

What do you invoke on the Intent to extract the bitmap?


回答1:


Try calling getExtras().get("data") and casting the result to a Bitmap.

See here for an example.




回答2:


On a related note, if you have the "crop" activity come up after taking the picture using intent.putExtra("crop", "true"), you'll get the cropped URI from getExtras().get("action").

I realize you've got this all fixed by now, just want to make sure no one tries to use this with crop and gets confused.

Reference: the apps-for-android LolCat activity.



来源:https://stackoverflow.com/questions/2451442/how-to-save-a-picture-to-a-file

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