gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 08:45:42 25 4
gpt4 key购买 nike

我在设备私有(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com