---
title: "纯C下的读写BMP文件代码"
author: "mmdev"
date: "2007-10-24T15:00:00Z"
tags: []
slug: "c-bmp"
draft: false
lastmod: "2007-10-24T15:00:00Z"
id: 990271
url: "https://mmdev.iteye.com/blog/990271"
---

纯C代码下读写BMP文件代码，简单易懂。

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)/\*\*//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*\*Copyright(c)2007,Shanghai  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*\*文件名称：read\_write\_bmp\_with\_C.c  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*\*编译:VisualC++/ANSIC/ISOC++  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*\*日期：2007.10.24  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include"stdio.h"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include"stdlib.h"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#definePIXPLINE320  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)typedefstructtagRGBQUAD...{//定义每个像素的数据类型  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)unsignedcharrgbBlue;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)unsignedcharrgbGreen;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)unsignedcharrgbRed;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}RGBQUAD;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)intbmp\_read(unsignedchar\*image,intxsize,intysize,char\*filename)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)charfname\_bmp\[128];  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)sprintf(fname\_bmp,"%s.bmp",filename);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)FILE\*fp;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(!(fp=fopen(fname\_bmp,"rb")))  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)return-1;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)unsignedcharheader\[54];  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fread(header,sizeof(unsignedchar),54,fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fread(image,sizeof(unsignedchar),(size\_t)(long)xsize\*ysize\*3,fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fclose(fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)return0;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)intbmp\_write(unsignedchar\*image,intxsize,intysize,char\*filename)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)unsignedcharheader\[54]=...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)0x42,0x4d,0,0,0,0,0,0,0,0,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)54,0,0,0,40,0,0,0,0,0,0,0,0,0,0,0,1,0,24,0,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)0,0,0,0  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)longfile\_size=(long)xsize\*(long)ysize\*3+54;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[2]=(unsignedchar)(file\_size&0x000000ff);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[3]=(file\_size&gt;&gt;8)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[4]=(file\_size&gt;&gt;16)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[5]=(file\_size&gt;&gt;24)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)longwidth=xsize;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[18]=width&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[19]=(width&gt;&gt;8)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[20]=(width&gt;&gt;16)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[21]=(width&gt;&gt;24)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)longheight=ysize;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[22]=height&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[23]=(height&gt;&gt;8)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[24]=(height&gt;&gt;16)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[25]=(height&gt;&gt;24)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)charfname\_bmp\[128];  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)sprintf(fname\_bmp,"%s.bmp",filename);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)FILE\*fp;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(!(fp=fopen(fname\_bmp,"wb")))  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)return-1;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fwrite(header,sizeof(unsignedchar),54,fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fwrite(image,sizeof(unsignedchar),(size\_t)(long)xsize\*ysize\*3,fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fclose(fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)return0;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)voidclonebmp(unsignedchar\*image,intxsize,intysize)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)bmp\_read(image,xsize,ysize,"orgbmp");//orgbmp为当前目录下的bmp文件名  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)bmp\_write(image,xsize,ysize,"clone\_bmp");//clone\_bmp为克隆的bmp文件名  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)/\*\*//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*名称：youwritetobmp()  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*功能：写入bmp文件  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*入口参数：RGBQUAD\*pixarr----要写入的像素数组指针,intxsize----图像宽度,intysize----图像高度,char\*filename--图像名称  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*出口参数：无  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*返回值：-1:错误；0：正确  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)intyouwritetobmp(RGBQUAD\*pixarr,intxsize,intysize,char\*filename)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)unsignedcharheader\[54]=...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)0x42,0x4d,0,0,0,0,0,0,0,0,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)54,0,0,0,40,0,0,0,0,0,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)0,0,0,0,0,0,1,0,24,0,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)0,0,0,0,0,0,0,0,0,0,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)0,0,0,0,0,0,0,0,0,0,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)0,0,0,0  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)inti;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intj;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)longfile\_size=(long)xsize\*(long)ysize\*3+54;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[2]=(unsignedchar)(file\_size&0x000000ff);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[3]=(file\_size&gt;&gt;8)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[4]=(file\_size&gt;&gt;16)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[5]=(file\_size&gt;&gt;24)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)longwidth;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(!(xsize%4))width=xsize;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)elsewidth=xsize+(4-xsize%4);//如不是4的倍数，则转换成4的倍数  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[18]=width&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[19]=(width&gt;&gt;8)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[20]=(width&gt;&gt;16)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[21]=(width&gt;&gt;24)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)longheight=ysize;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[22]=height&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[23]=(height&gt;&gt;8)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[24]=(height&gt;&gt;16)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)header\[25]=(height&gt;&gt;24)&0x000000ff;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)charfname\_bmp\[128];  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)sprintf(fname\_bmp,"%s.bmp",filename);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)FILE\*fp;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(!(fp=fopen(fname\_bmp,"wb")))  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)return-1;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fwrite(header,sizeof(unsignedchar),54,fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)RGBQUADzero=...{0,0,0};//不足字节，用zero填充  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)for(j=0;j&lt;ysize;j++)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if(!(xsize%4))...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)for(i=0;i&lt;xsize;i++)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fwrite(pixarr+i,sizeof(RGBQUAD),1,fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)else  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)for(i=0;i&lt;xsize;i++)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fwrite(pixarr+i,sizeof(RGBQUAD),1,fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)for(i=xsize;i&lt;xsize+(4-xsize%4);i++)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fwrite(&zero,sizeof(RGBQUAD),1,fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fclose(fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)return0;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)intmain()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)unsignedchar\*image;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intxsize=320;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intysize=163;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)RGBQUADpixarray\[PIXPLINE];//一行像素值数组  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)image=(unsignedchar\*)malloc((size\_t)xsize\*ysize\*3);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(image==NULL)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)return-1;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)clonebmp(image,xsize,ysize);//功能一：实现一副图像的拷贝  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)youwritetobmp(pixarray,xsize,ysize,"yourimage");