如何读取存储在内存中的图像文件?

dwa*_*esh 7 android image

在我的Android应用程序中,我使用以下代码将图像文件存储在内部存储器中 -

FileOutputStream fos = con.openFileOutput(fileName, con.MODE_PRIVATE);
fos.write(baf.toByteArray()); // baf - ByteArrayBuffer
fos.close();
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我从内部显示这个图像文件在一个激活?

Kon*_*rov 17

试试这个:

ImageView imageView = (ImageView) findViewById(R.id.image);
File filePath = getFileStreamPath(fileName);
imageView.setImageDrawable(Drawable.createFromPath(filePath.toString()));
Run Code Online (Sandbox Code Playgroud)

在上面的代码片段中R.id.imageImageView您布局中某处的ID .fileNameString您在openFileOutput调用中使用的文件的包含名称.