资源描述:
《读取并显示一幅bmp图象编程流程》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、一、BMP:包括BITMAPFILEHEADER(位图文件头)、BITMAPINFOHEADER(位图信息头)、Palette(调色板)、ImageData(位图数据)构成。DDB:是设备相关位图文件,结构如下:TypedefstructtagBITMAP{IntbmType;//通常为0IntbmWidth;//像素点宽度IntbmHeight;//像素点高度IntbmWidthBytes;//每行数据的字节数,必为偶数BYTEbmPlanes;//显示设备的色位面数BYTEbmBitsPixel;//每
2、像素的位数VoidFAR*bmBits;//指向像素数据的指针};位图必须在同类设备中显示,并且此设备在位平面或彩色上与原设备有同样的色彩安排,否则色彩可能完全失真。DIB是设备无关位图文件,由3部分构成:BITMAPINFOHEADER(位图信息头)、Palette(调色板)、ImageData(位图数据)。它的结构和BMP文件结构相似,它实际就是BMP文件去掉BITMAPFILEHEADER(位图文件头),即一个BITMAPINFOHEADER(位图信息头)结构后面接上调色板再加上图像数据。BMP文件有
3、两种显示方法,首先将BMP文件读成DIB格式,当显示时,一种是直接将DIB显示,另一种是将DIB转化为DDB,再显示DDB。几个数据类型:CfileLPCTSTRUINT几个函数:1、virtualBOOLOpen(LPCTSTRlpszFileName,UINTnOpenFlags,CFileException*pError=NULL);ReturnValue:Nonzeroiftheopenwassuccessful;otherwise0.ThepErrorparameterismeaningfulon
4、lyif0isreturned.LpszFileName:Astringthatisthepathtothedesiredfile.NOpenFlags:definesthefile’ssharingandaccessmode.Itspecifiestheactiontotakewhenopeningthefile.PError:Apointertoanexistingfile-exceptionobjectthatwillreceivethestatusofafailedoperation.如:Open(
5、filename,CFile::modeRead
6、CFile::shareDenyNone,NULL)==0)2、intAfxMessageBox(LPCTSTRlpszText,UINTnType=MB_OK,UINTnIDHelp=0);3、TheHeapAllocfunctionallocatesablockofmemoryfromaheap.Theallocatedmemoryisnotmovable.4LPVOIDHeapAlloc(HANDLEhHeap,//handletotheprivate
7、heapblockDWORDdwFlags,//heapallocationcontrolflagsDWORDdwBytes//numberofbytestoallocate);4、memcpy:Copiescharactersbetweenbuffers5、HeapFree:freesamemoryblockallocatedfromaheapbytheHeapAllocorHeapReAllocfunction.6、SetDIBitsToDevice:setsthepixelsinthespecifie
8、drectangleonthedevicethatisassociatedwiththedestinationdevicecontextusingcolordatafromadevice-independentbitmap(DIB).intSetDIBitsToDevice(HDChdc,//handletodevicecontextintXDest,//x-coordinateofupper-leftcornerof//dest.rect.intYDest,//y-coordinateofupper-le
9、ftcornerof//dest.rect.DWORDdwWidth,//sourcerectanglewidthDWORDdwHeight,//sourcerectangleheightintXSrc,//x-coordinateoflower-leftcornerof//sourcerect.intYSrc,//y-coordinateoflower-leftcornerof//sourcerect.UINT