如何将我的图像保存为BMP格式?

4

我知道保存位图文件时应该使用压缩方法。

FileOutputStream fos = new FileOutputStream(imagefile);

bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();

但是我想将我的图像保存为BMP格式,而“Bitmap.CompressFormat”仅支持PNG和JPEG。我该如何将我的图像文件保存为BMP格式?

谢谢。


以下是程序相关内容的翻译:将位图保存为BMP文件格式(Android) - Viktor Brešan
1个回答

0

你可以使用copyPixelsToBuffer将位图像素存储到缓冲区中,然后将缓冲区写入SD卡。


我已经尝试过了,但是没有得到结果:`FileOutputStream fos = new FileOutputStream(imagefile); ByteBuffer bf = ByteBuffer.allocate(width * height * 4); bitmap.copyPixelsToBuffer(bf); fos.write(bf.array()); fos.flush(); fos.close(); return true;` - Bobs
抱歉,我刚才误解了文档。抱歉。 - Blackbelt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接