【发布时间】:2018-02-05 15:52:06
【问题描述】:
我想在图像查看器意图中显示我从下一个下载的 png 或 jpg,但无法正常工作。
Bitmap bmp = getImageBitmap(jpg);
String path = getFilesDir().getAbsolutePath() + "/test.png";
File file = new File(path);
FileOutputStream fos = new FileOutputStream(file);
bmp.compress( CompressFormat.PNG, 100, fos );
fos.close();
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "image/png");
startActivity(intent);
我知道位图下载正常(使用相同的例程在我的应用程序的其他地方提供我的 ImageView 实例) - 我认为它写入文件正常,我可以在磁盘上看到它并且文件大小是正确的。 Intent 启动但抛出异常:
ERROR/ImageManager(1345): 得到异常解码位图 java.lang.NullPointerException
然后新活动就在那里,空白。这是如何工作的?
【问题讨论】:
标签: android