在ImageView中显示存储在内部存储器中的图像?我究竟做错了什么?

问题描述:

我先存储在内部存储器中的图像是这样的:在ImageView中显示存储在内部存储器中的图像?我究竟做错了什么?

FileOutputStream fos = context.openFileOutput("myimage.png", Context.MODE_PRIVATE); 
bitmap.compress(CompressFormat.PNG, 100, fos); 
fos.close(); 

然后我在ImageView显示这样说:

File filepath = context.getFileStreamPath("myimage.png"); 
Uri uri = Uri.parse(filepath.toString()); 
myImageView.setImageUri(uri); 

但图像不会出现在ImageView。由于某些限制,我不能在这里使用setImageBitmap()。谁能告诉我我哪里错了?

感谢您的帮助!

你可以尝试以下方法:

相反的context.getFileStreamPath("myimage.png");你可以尝试Uri uri = Uri.parse(getFilesDir().getPath() + "/myimage.png");

+0

尝试过这种方法。仍然没有图像:( – 2012-08-12 14:21:35

+0

您是否在清单中添加了'? 位图是如何声明的? – FredFloete 2012-08-12 15:07:38

+0

WRITE_EXTERNAL_STORAGE不是必需的,因为我使用内部用于读/写操作,对于位图,我首先打开图库,然后当选择图像时,我使用BitmapFactory.decodeFile(),这部分工作正常,问题出在ImageView部分。 – 2012-08-12 15:31:02

BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), getFileStreamPath("myimage.png").getAbsolutePath()); 

imageView.setImageDrawable(bitmapDrawable); 

Bitmap b = BitmapFactory.decodeFile(getFileStreamPath("myimage.png").getAbsolutePath()); 
+0

Bitmap b = BitmapFactory.decodeFile(getFilesDir()。getAbsolutePath()+“/myimage.png”); – 2013-12-07 06:19:28