【问题标题】:Reading image from private storage android从私有存储android读取图像
【发布时间】:2015-04-18 04:13:44
【问题描述】:

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

    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();

然后我想读取该图像并将其存储为位图以将其显示给用户,我不知道该怎么做才能做到这一点!我想再次从私有存储中读取图像,然后将其转换为位图。 有什么经验吗?

【问题讨论】:

  • 这可能不是一个好主意,因为用户可以删除该图像。你为什么要那样做?

标签: android image bitmap fileinputstream fileoutputstream


【解决方案1】:

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

首先,获取一个输入流:

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

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

Bitmap bmp = BitmapFactory.decodeStream(input);

之后别忘了关闭你的输入流!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-01
    • 2017-07-05
    • 2020-02-17
    • 2016-12-07
    • 2020-11-02
    • 1970-01-01
    • 2022-06-24
    • 2012-04-21
    相关资源
    最近更新 更多