从私人存储android读取图像

时间:2015-02-17 12:52:03

标签: android image bitmap fileinputstream fileoutputstream

我已将一些图像存储在设备专用存储中,例如:

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

然后我想读取该图像并将其存储为位图以向用户显示,我不知道如何做到这一点!我想从私有存储中再次读取图像,然后将其转换为位图。 任何经历?

1 个答案:

答案 0 :(得分:3)

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

首先,获取输入流:

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

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

Bitmap bmp = BitmapFactory.decodeStream(input);

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