且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

位图保存为JPEG文件

更新时间:2021-08-04 22:02:22

你可以试试这个:

 public static final int BUFFER_SIZE = 1024 * 8;
 static void writeExternalToCache(Bitmap bitmap, File file) {
    try {
        file.createNewFile();
        FileOutputStream fos = new FileOutputStream(file);
        final BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER_SIZE);
        bitmap.compress(CompressFormat.JPEG, 100, bos);
        bos.flush();
        bos.close();
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {

    }

}

它的作品在我的code,因此,如果它不能正常工作,试图找到错误:

it works in my code, so if it's not work, try to find error:

1,位图显示正确的?

1.the bitmap display right ?

2.where是位图保存文件?文件中有一些限制?像大小或...

2.where is the bitmap save file? the file has some limit? like size or ...

如果错误是你的文章的原因,你可以在c位图再次使用尝试去$ C $ Bitmap.Config.RGB_565

if the error is your post reason, you can try decode the bitmap again using Bitmap.Config.RGB_565.