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

2023-09-06 03:05:17 作者:听风念

在我的Andr​​oid应用程序,我的内部存储器使用下面code存储图像文件 -

In my android application I an storing an image file in internal memory using below code-

FileOutputStream fos = con.openFileOutput(fileName, con.MODE_PRIVATE);
fos.write(baf.toByteArray()); // baf - ByteArrayBuffer
fos.close();

任何一个可以请帮我读从内部显示它这个图像文件中的activty?

Can any one please help me to read this image file from internal display it in an activty?

推荐答案

试试这个:

ImageView imageView = (ImageView) findViewById(R.id.image);
File filePath = getFileStreamPath(fileName);
imageView.setImageDrawable(Drawable.createFromPath(filePath.toString()));

在上面的代码 R.id.image 的ImageView 地方在你的布局ID。 文件名是在 openFileOutput 调用。

In the above snippet R.id.image is id of ImageView somewhere in your layout. fileName is a String containing name of the file you used in openFileOutput call.