android - 从私有(private)存储android读取图像

标签 android image bitmap fileinputstream fileoutputstream

我在设备私有(private)存储中存储了一些图像,例如:

    InputStream inputStream = response.getEntity().getContent();
    FileOutputStream fileOutputStream = openFileOutput("someImage.jpeg", cont.MODE_PRIVATE);
    int read = 0;
    byte[] buffer = new byte[32768];
    while((read = inputStream.read(buffer)) > 0) {
        fileOutputStream.write(buffer, 0, read);
    }
    fileOutputStream.close();
    inputStream.close();

然后我想读取该图像并将其存储为位图以将其显示给用户,我不知道该怎么做才能完成此任务!我想从私有(private)存储中再次读取图像,然后将其转换为位图。 有什么经验吗?

最佳答案

您需要的是BitmapFactory.decodeStream(String name) .

首先,获取输入流:

InputStream input = openFileInput("someImage.jpeg");

接下来,用它来获取位图:

Bitmap bmp = BitmapFactory.decodeStream(input);

之后不要忘记关闭输入流!

关于android - 从私有(private)存储android读取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28561964/

相关文章:

Java JComponent.getGraphics() 始终返回 null

c# - 在图片框上绘图时位置错误

android - 在使用 picasso 将图片调整为 imageview 后,如何获取图片的结果位图

android - 如何处理android中 Activity 之间的内存

android - 隐藏/禁用 Chrome 自定义选项卡中的默认菜单

android - 函数如何知道哪个可点击的textView已通过onClick调用了它?

java - 自动从数据库中获取URL

android - 用于旧版 Android 设备的 ARCore

android - 位图图像内存不足

android - 在android的位图上将白色转换为透明