如何保存图片到一个文件? [英] How to save a picture to a file?
问题描述
我试图用一个标准的意图,将拍摄一张照片,然后让核准或重修。然后我想将图片保存到文件中。
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.
下面是我使用的意图:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult( intent, 22 );
借助文档说:
调用者可以通过一个额外的EXTRA_OUTPUT来控制这
图像将被写入。如果EXTRA_OUTPUT不是present,那么
小尺寸图像返回作为额外的字段Bitmap对象。如果
该EXTRA_OUTPUT是present,那么全尺寸的图像会
写入EXTRA_OUTPUT的URI值。
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.
我没有通过额外的输出,我希望能得到一个位图对象传递到的onActivityResult的意图的额外字段()
(这个要求)。那么,/你怎么提取呢?意图有一个 getExtras()
,但返回一个包,和捆绑想要一个密钥字符串给你的东西回来了。
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?
推荐答案
尝试调用 getExtras()。获得(数据)
和铸造结果为位图
。
Try calling getExtras().get("data")
and casting the result to a Bitmap
.
这篇关于如何保存图片到一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!