加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

给一个rgb888的纯数据插入bmp头文变成bmp图像

(2014-06-02 18:49:48)
标签:

365

bmp图像生成

#include

#include

 

#pragma pack(1) 

if(fpW==NULL)

{

    printf("Write the test1.bmp file failed !\n");

    exit(1);

}

fpR = fopen("640-480.rgb", "rb"); 

if(fpR == NULL){

    printf("Read file failed !\n");

    exit(1);

}

bmpFHeader.bfType=0x4D42; //16进制

//  bmpFHeader.bfType=19778;

bmpFHeader.bfSize=54L+640*480*3;

bmpFHeader.bfReserved1=0;

bmpFHeader.bfReserved2=0;

bmpFHeader.bfOffBits=54L;

 

bmpInfo.biSize=40L;

bmpInfo.biWidth=640;

bmpInfo.biHeight=480;

bmpInfo.biPlanes=1;

bmpInfo.biBitCount=24;

bmpInfo.biCompression=0;

bmpInfo.biSizeImage=640*480*3;

bmpInfo.biXPelsPerMeter=0;

bmpInfo.biYPelsPerMeter=0;

bmpInfo.biClrUsed=256;

bmpInfo.biClrImportant=256;

fwrite(&bmpFHeader,sizeof(BITMAPFILEHEADER),1,fpW);

fwrite(&bmpInfo,sizeof(BITMAPINFOHEADER),1,fpW);

fseek(fpW, 54L, SEEK_SET);

while(fread(buf, 1, 640 * 480 * 3, fpR) != '\0')

    fwrite(buf, 1, 640 * 480 * 3, fpW);

 

fclose(fpR);

fclose(fpW);

return 0; 

 

}

 

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有