2011-10-02 39 views
4

我知道我应该使用compress方法来保存位图文件。如何将图像保存为BMP格式?

FileOutputStream fos = new FileOutputStream(imagefile); 

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

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

感谢,

回答

1

可以使用copyPixelsToBuffer

存储位图像素到缓冲区,然后,比写您的缓冲区插入SD。

+0

我做到了,但没有得到结果: 'FileOutputStream fos = new FileOutputStream(imagefile); \t \t ByteBuffer bf = ByteBuffer.allocate(width * height * 4); \t \t bitmap.copyPixelsToBuffer(bf); \t \t fos.write(bf.array()); \t \t fos.flush(); \t \t fos.close(); \t \t return true;' – breceivemail

+0

对不起,我只是误解了文档。抱歉 – Blackbelt