如何将图片保存到文件? [英] How to save a picture to a file?

查看:181
本文介绍了如何将图片保存到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用标准Intent,它会拍摄照片,然后允许批准或重新拍摄。

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不存在,则
小尺寸的图像作为额外字段中的Bitmap对象返回。如果
存在EXTRA_OUTPUT,那么全尺寸图像将是
写入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()(对于这个请求)的Intent的额外字段中获得一个Bitmap对象。那么在哪里/你如何提取呢? Intent有一个 getExtras(),但返回一个Bundle,Bundle想要一个键字符串给你一些东西。

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.

推荐答案

尝试调用 getExtras ).get(data)并将结果转换为 Bitmap

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

查看示例

这篇关于如何将图片保存到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆