生成图片的要求:图像格式采用单色位图文件格式(BMP) 要求bmp的位深度为1
参考:
代码有点小瑕疵 : bitmap的图片宽度要求是:8的整数倍
/**
* 将Bitmap存为 .bmp格式图片
*
* @param bitmap
*/
public void saveBmp(Bitmap bitmap) {
if (bitmap == null)
return;
// 位图大小
int nBmpWidth = bitmap.getWidth();
int nBmpHeight = bitmap.getHeight();
// 图像数据大小
int bufferSize = nBmpHeight * nBmpWidth /8 + 4*2;
try {
// 存储文件名
String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "test.bmp";
File file = new File(filename);
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fileos = new FileOutputStream(filename);
// bmp文件头
int bfType = 0x4d42;
l