sha*_*arp 0 android loading bitmap
我将位图图像保存在内部存储中,但我无法重新显示它.我已经研究了很长时间但我还没有找到.
public static void saveImages(Activity activity) throws IOException
{
for (int i=0; i<categories.getItems().length; i++) {
OutputStream os2 = activity.openFileOutput(categories.getItems()[i].getName(),
Context.MODE_WORLD_READABLE);
OutputStreamWriter osw2 = new OutputStreamWriter(os2);
Bitmap bmp = ((BitmapDrawable)categories.getItems()[i].getCategoryImage()).getBitmap();
bmp.compress(Bitmap.CompressFormat.PNG, 90, os2);
osw2.close();
}
}
Run Code Online (Sandbox Code Playgroud)
此代码可成功保存图像.我将重新显示文件中的图像.谢谢
尝试这个
File f=new File(yourdir, imagename);
Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
Run Code Online (Sandbox Code Playgroud)
试试这段代码:用于openFileInput
获取您保存的流,然后解码它们:
for (int i=0; i<categories.getItems().length; i++) {
InputStream is = activity.openFileInput(categories.getItems()[i].getName());
Bitmap b = BitmapFactory.decodeStream(is);
// do whatever you need with b
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6831 次 |
最近记录: |