android - 如何将图片保存到文件?

标签 android file camera save

我正在尝试使用标准 Intent 来拍照,然后允许批准或重拍。然后我想把图片保存到文件中。

这是我正在使用的 Intent:

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

startActivityForResult( intent, 22 );

documentation说:

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的extra字段中得到一个Bitmap对象(对于这个请求)。那么你在哪里/如何提取它? Intent 有一个 getExtras(),但它返回一个 Bundle,而 Bundle 需要一个 key 字符串来给你一些东西。

您在 Intent 上调用什么来提取位图?

最佳答案

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

See here for an example .

关于android - 如何将图片保存到文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2451442/

相关文章:

ios - AVCaptureVideoPreviewLayer(相机预览)在移动到背景和返回后卡住/卡住

java - Android 为什么我在为启动画面膨胀图层列表时出现错误

android - 如何从 UIAutomator 运行 "adb commands"

java - 从程序文件获取文件

Java 通过套接字发送和接收文件 (byte[])

c++ - 如果图像是 `==`,OpenCV 如何让 bool 为真,否则如何让 bool 为假?

c++ - OpenGL - 第一人称相机矩阵的问题

java - 手机上的 Android 主机网站

Android Dropbox 客户端因 v1 退役而失败

file - Camel 文件组件中的动态输入/输出文件夹位置