保存位图到磁盘/画廊的Andr​​oid 4.3 [英] Saving a bitmap to disk/gallery in Android 4.3

查看:135
本文介绍了保存位图到磁盘/画廊的Andr​​oid 4.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用该系统保存<一的方式href="https://android.googlesource.com/platform/frameworks/base/+/master/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java">screenshots我的位图保存到磁盘和画廊。这在Android的4.2和前,但不是在Android的4.3。

I've been using the way the system saves screenshots to save my bitmaps to the disk and gallery. This works in Android 4.2 and before but not in Android 4.3.

相关code:

Uri imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
OutputStream out = resolver.openOutputStream(uri);

全部code <一个href="https://github.com/f2prateek/Device-Frame-Generator/blob/master/app/src/main/java/com/f2prateek/dfg/core/DeviceFrameGenerator.java#L178">here.

在4.3(新的Nexus 7)不过,我得到一个 FileNotFoundException异常的第二行。我看不出在4.3相关的任何更改这个在网站

In 4.3 (new Nexus 7) however, I get a FileNotFoundException on the second line. I couldn't see any changes in 4.3 relevant to this on the website.

那么,什么是正确的方式来保存图像到磁盘和画廊?

So what is the right way to save an image to the disk and gallery?

验证:

  • 在存储上安装有该方法
  • 在imageUri不为空(通常是像的内容://媒体/外部/图片/媒体/ 2034)
  • 在清单有权android.permission.WRITE_EXTERNAL_STORAG​​E

推荐答案

这是我的样子保存位图多媒体的:

This is the way I save bitmaps to the Gallery:

Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri; //instantiate Uri with location of image
mediaScanIntent.setData(contentUri);
context.sendBroadcast(mediaScanIntent);

这篇关于保存位图到磁盘/画廊的Andr​​oid 4.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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