【发布时间】:2017-03-26 16:46:15
【问题描述】:
我正在使用 Photopicker Library Link 从 SD 卡中检索图像集合。我需要将这些图像保存到位图中,以便将其传递给另一个类(该类只接受位图Link)。
在下面的代码中,我正在检索从图像选择器中选择的图像集合。
public byte[] generateGIF(Photo[] collection) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
AnimatedGifEncoder encoder = new AnimatedGifEncoder();
Bitmap[] allimages = null ; **// Array of Bitmap images**
int i=0;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
encoder.start(bos);
for (Photo photo : collection) {
Log.i("After", "URI: " + photo.getUri());
//Photo[] is a array of Photo class that holds the array of the images selected via Image Picker.
// getUri() is a method in Photo class to retrieve the Uri of the Image.
allimages[i] = BitmapFactory.decodeFile(photo.getUri().getPath(),options);
i++;
encoder.addFrame(allimages[i]);
}
i=0;
encoder.finish();
//Toast.makeText(MainActivity.this, "Saved.", Toast.LENGTH_SHORT).show();
return bos.toByteArray();
}
执行时我遇到错误。 检索错误“BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /external/images/media/45 (No such file or directory)”
我也尝试了以下解决方案,但也没有用。
//allimages[i] = MediaStore.Images.Media.getBitmap(this.getContentResolver(),photo.getUri());
下面也试过了
// allimages[i] = BitmapFactory.decodeFile(photo.getUri().getPath());
请帮我解决这个问题。 提前谢谢...
:Log.i("After", "URI:" + photo.getUri()); 之后的错误日志
03-27 21:16:12.624 2393-2393/com.patel.pritesh.myapplication I/After: URI: content://media/external/images/media/44 03-27 21:16:12.624 2393-2393/com.patel.pritesh.myapplication I/Okay: URI: content://media/external/images/media/44 03-27 21:16:12.624 2393-2393/com.patel.pritesh.myapplication E/BitmapFactory: 无法解码流: java.io.FileNotFoundException: content:/media/external/images/media/44 (没有这样的文件或目录) 03-27 21:16:12.624 2393-2393/com.patel.pritesh.myapplication W/System.err: java.lang.NullPointerException: 尝试写入空数组 03-27 21:16:12.624 2393-2393/com.patel.pritesh.myapplication W/System.err: 在 com.patel.pritesh.myapplication.MainActivity.generateGIF(MainActivity.java:184) 03-27 21:16:12.625 2393-2393/com.patel.pritesh.myapplication W/System.err: at com.patel.pritesh.myapplication.MainActivity.GifCreator(MainActivity.java:155)
【问题讨论】: