C++实现保存24位BMP图像
我想要保存的是24位真彩图,对于24位真彩图,可以不需要颜色表,也就是说54个字节后面紧跟的就是图像数据,所以我没有写入文件(不知道这是不是我保存后的图像打不开的原因)
BITMAPFILEHEADER,BITMAPINFOHEADER文件的书写如下:
int size;
size=3*imageWidth;
if (3*imageWidth%4)
size+=4-3*imageWidth%4;
size*=imageHeight;
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
bih.biBitCount=24;
bih.biClrImportant=0;
bih.biClrUsed=0;
bih.biCompression=BI_RGB;
bih.biHeight=imageHeight;
bih.biPlanes=1;
bih.biSize=sizeof(BITMAPINFOHEADER);
bih.biSizeImage=size;
bih.biWidth=imageWidth;
bih.biXPelsPerMeter=0;
bih.biYPelsPerMeter=0;
bfh.bfReserved1=bfh.bfReserved2=0;
bfh.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+size;
bfh.bfType=((WORD)('M'<<8)|'B');
bfh.bfOffBits=54;
stream=fopen("b.bmp","wb");
if(stream==NULL) return;
fwrite(&bfh,sizeof(bfh),sizeof(bfh),stream);
fwrite(&bfh,sizeof(bfh),sizeof(bih),stream);
for(i=0;i<ImageHeight;i++)
for(j=0;j<ImageWidth;j++)
{
{
fwrite(&buffertemp[i][j*3],1,sizeof(BYTE),stream);
fwrite(&buffertemp[i][j*3+1],1,sizeof(BYTE),stream);
fwrite(&buffertemp[i][j*3+2],1,sizeof(BYTE),stream);
}
}
fclose(stream);
请问大家问题出在哪里,如何修改,可以不要颜色表的吧?
BITMAPFILEHEADER,BITMAPINFOHEADER文件的书写如下:
int size;
size=3*imageWidth;
if (3*imageWidth%4)
size+=4-3*imageWidth%4;
size*=imageHeight;
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
bih.biBitCount=24;
bih.biClrImportant=0;
bih.biClrUsed=0;
bih.biCompression=BI_RGB;
bih.biHeight=imageHeight;
bih.biPlanes=1;
bih.biSize=sizeof(BITMAPINFOHEADER);
bih.biSizeImage=size;
bih.biWidth=imageWidth;
bih.biXPelsPerMeter=0;
bih.biYPelsPerMeter=0;
bfh.bfReserved1=bfh.bfReserved2=0;
bfh.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+size;
bfh.bfType=((WORD)('M'<<8)|'B');
bfh.bfOffBits=54;
stream=fopen("b.bmp","wb");
if(stream==NULL) return;
fwrite(&bfh,sizeof(bfh),sizeof(bfh),stream);
fwrite(&bfh,sizeof(bfh),sizeof(bih),stream);
for(i=0;i<ImageHeight;i++)
for(j=0;j<ImageWidth;j++)
{
{
fwrite(&buffertemp[i][j*3],1,sizeof(BYTE),stream);
fwrite(&buffertemp[i][j*3+1],1,sizeof(BYTE),stream);
fwrite(&buffertemp[i][j*3+2],1,sizeof(BYTE),stream);
}
}
fclose(stream);
请问大家问题出在哪里,如何修改,可以不要颜色表的吧?
...全文
相关推荐
bmp 真彩色转灰度
BMP图像文件的操作,编写C++程序,可以将一个标准24bit真彩色BMP文件中三基色图像提取出来存成独立的8bit灰度图像(BMP)
C/C++ BMP(24位真彩色)图像处理(2)------图像の截取
对上一篇博客《图像处理模板---针对bmp图像数据区的操作和输出处理完成图像》
bmp2raw.cpp.tar.gz_RAW_bmp raw_bmp to raw_bmp2raw_raw to bmp
Convert BMP to RAW file
C++读取保存BMP图像
C++读取保存BMP图像,包括8位,24位的读取和保存,灰度图的转换,不使用任何已有读取、转换、保存等库函数。跨平台使用,理论上Linux与Windows上均可使用,Windows上测试成功。
vc bmp 转 ico
将一个图片转成ico,方便添加资源.......


图形处理/算法
