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

Posted

技术标签:

【中文标题】如何将我的图像保存为 BMP 格式?【英文标题】:How can I save my image as BMP format? 【发布时间】:2011-10-02 09:28:47 【问题描述】:

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

FileOutputStream fos = new FileOutputStream(imagefile);

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

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

谢谢,

【问题讨论】:

在这里回答:***.com/questions/22909429/… 【参考方案1】:

你可以使用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; 对不起,我误解了文档。对不起

以上是关于如何将我的图像保存为 BMP 格式?的主要内容,如果未能解决你的问题,请参考以下文章