如果您从该Drawable创建一个Bitmap
,然后将其保存到文件,最好的解决方案是。
用此方法可绘制得到位图:
Drawable yourDrawable;
Bitmap bitmap = ((BitmapDrawable)yourDrawable).getBitmap();
创建从位图文件:
//create a file to write bitmap data
File f = File(context.getCacheDir(), filename);
f.createNewFile();
//Convert bitmap to byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();
//write the bytes in file
FileOutputStream fos = new FileOutputStream(f);
fos.write(bitmapdata);
fos.flush();
fos.close();
不要忘了明显的权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
完成这一步之后,你可以使用Universal Image Loader
将文件加载到您的ImageView
你能解释一下你的问题吗? –
@Ultimo_m检查编辑... – user222
请参阅我编辑的答案 –