如何将gif等图片格式在解析过程中解码得到的Bitmap转存为图片呢?Bitmap.java中提供了compress的方法,可以将Bitmap转换成文件,与BitmapFactory.java中的decodeStream方法相对应。下面是这两个方法的函数原型:
public static Bitmap decodeStream(InputStream is);
public boolean compress(CompressFormat format, int quality, OutputStream stream);
下面是FileUtils.java中的一段代码,先用decodeStream将系统res中的图片解码成Bitmap,然后再用compress转存为文件:
final File mf = new File(context.getFilesDir(), filename);
if (!mf.exists()) {
Bitmap bitmap = null;
FileOutputStream fos = null;
InputStream is = null;
try {
is = context.getResources().openRawResource(maskRawResourceId);
bitmap = BitmapFactory.decodeStream(is);
if (bitmap == null) {
throw new IllegalStateException("Ca