在我的 android 应用程序中,我使用以下代码将图像文件存储在内部存储器中-
FileOutputStream fos = con.openFileOutput(fileName, con.MODE_PRIVATE);
fos.write(baf.toByteArray()); // baf - ByteArrayBuffer
fos.close();
谁能帮我在 Activity 中从内部显示读取这个图像文件?
最佳答案
试试这个:
ImageView imageView = (ImageView) findViewById(R.id.image);
File filePath = getFileStreamPath(fileName);
imageView.setImageDrawable(Drawable.createFromPath(filePath.toString()));
在上面的代码 fragment 中,R.id.image
是布局中某处 ImageView
的 ID。 fileName
是一个 String
,包含您在 openFileOutput
调用中使用的文件的名称。
关于android - 如何读取存储在内存中的图像文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3802695/