drawable保存到文件

//Bitmap.CompressFormat.PNG
public void drawableToFile(Drawable drawable, String filePath, Bitmap.CompressFormat format) {
    if (drawable == null)
        return;

    try {
        File file = new File(filePath);

        if (file.exists())
            file.delete();

        if (!file.exists())
            file.createNewFile();

        FileOutputStream out = null;
        out = new FileOutputStream(file);
        ((BitmapDrawable) drawable).getBitmap().compress(format, 100, out);
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}


猜你喜欢

转载自blog.csdn.net/yongwoozzang/article/details/80193808
今日推荐