利用位图实现大数据量绘图的快速显示(2)
发布时间:2021-06-08
发布时间:2021-06-08
位图 矢量图 计算机图像
i
1i,。|。i、.,。≯j。
:襄薷囊。蠢麓麓4繁”’譬
强一.皤鬏ApHl£S
■
!”?
。:’。“’i譬弼
i,Il
≠、F
’
-㈡
l
i。“匿黪臻辍
//returnhandIetOtheDlB
return
G疑APHlCS
她7箍
7一
memset(&bi,O,sizeof(bi)):
bi.biSize=sizeof(BITMAPINFOHEADER):bi.biPlanes=1:
bi.biComDression=BLRGB:
//qetandstOredimensiOnsofbitmapBITMAPbm:
GetObiect(sizeof(bm),(LPSTR)&bm):
hDIB:
6)给该类添加void蹦nt(cDc。pDc)公有成员函数,用来
实现位图到打印机的打印。主要代码为:
.ntbmData:
//pDC为打印机设备环境指针
HANDLEhDIB=CreateDlB(&bmData):
//get
bi.biWidth=bm.bmWidth:
bi.biHeight=bm.bmHeight;
//getnumberOfbitsrequiredperpi×el
intbits=bm.bmPlanes¥bm.bmBitsPjxeI:_f(bits<=1)bi.biB.tCount=1:else.f(bits<兰4)bi.b_B_tCount=4:else-f(b.ts<=8)bi.biBitCount=8:
eJse
memOrypointerstOtheDlB’sheaderanddatabits
LPBn。MAPlNFOHEADERIDDlBHdr=APlNFOHEADER)::
GIobalLock(hDIB):
LPSTRfpDIBBjts=《LPSTR)lpDIBHdr+bmData:DDC一>SetStretchBItMode(COLORONCOLOR):CRect
rect《0,O,m—yVidth,m—Height):
DDC一>DPtoLP(&rect):
::StretchDIBits(pDC一>m-hDC,
//打印机设备环境
0,O,mjitRect.Width(),一m_BjtRect.Height(),//此
//
source
处用用逻辑坐标
0,O,m—j~idth,mj_{eight,
sions(useaIlofbitmap)(LPBITMAPINFO)IpDIBHdr.
bitmap
dimen
bi.biBitCount=24://caIculatecoIorint
tabIesize
lpDIBBits,//bitmappicturedata
//bitmapheaderinfo
DlB』GB』OLORS,//specifycoIortabIehasRGBVafues
SRCCOPY//sirnpIesourcetodestinationcOpy
):
丰
biColorSize=0:
.f(bi.biBitCount!=24)biCoIorSize=(1<<bi.biBjtCount):
bjCoIorSize木=sizeof(RGBQUAD):
//calculateDicturedata
size
bi.biSizeImage=(DWORD).bm.bmWidth
bi.biBitCount://bitsperrOw
bi.biSizeImage=(((bi.biSizeImage)
+31)/32)
//cIeanuD
::GlobaIUnlock(hDIB):
木
4://DWORD
aligned
::GfobalFree(hDlB):
retum:
bi.biSizeImage水=bm.bmHeight://bytesrequiredfor
whOIebitmaD
//retumsizetOcafer{ncasetheVwanttOsavetOfiIe
.f(pbmD8ta)
8
7)最后为该类添加voidsaveBitmap(cstringsFile)公共成员函数,用来保存位图。
实现代码主要为:
//create
int
a
DbmData=bibiSize+biCoIOrSize:
cOIOr
DIBbjtmaD
////getDIBc0IortabIeandpicturedata
//a|JOcateahunkOfmemOrVtOhOIdheader,
tabIeandDicturedata
HANDLE
bmData:
hDIB=CreateDlB(&bmData):
memOrypOintertOit
HANDLE//getLPBYTE
a
hDIB=::GlobafA||oc(GHND.bi.biSize+bi-memOrypOintertOthishunkbyIOcking.t
LPBlTMAPlNFOHEADERfDbi=
headerstructureintOhunk
ColorSjze+bi.biSizeImage):
//get
a
IpBitmap=(LPBYTE)::GIobalLock(hDlB);
intbmSjze=::GlobaISize(hDlB):
//createfile
CFi{ef¨e:
flIe.Open(sFi『e,CFi|e::modeCreateCFife::modeWrite)://writethebItmaDheaderBITMAPFILEHEADERbmfh:
(LPBITMAPINFOHEADER)::GIobaILock(hDIB):
//cOpy
Our
¥Ipbi=bi:
//get
a
deviceCOntextandselectCDCdc:
Our
bitmap
s
paIetteintoit
bmfh.bfTYpe=’MB7://(actuaIIy7BM’forbItmap)
bmfh.bfSize=sizeof(BITMAPFlLEHEADER)+bmSize:bmfh.bfReservedl=O:bmfh.bfReserved2=O:bmfh.bfoffBits=bmData:
dc.Attach(::GetDC(NULL)):
CPalette水pPal=dc.Se|ectPaIette(mJ3PaIette,FALSE):
dc.RealizePaIette():
//Ioad
Oicturedata
our
memorvhunkwjththecoIortableand
fiIe.Write(&bmfh,sizeof(BfTMAPFJLEHEADER)):
//writethebitmapbOdV
::GetDlBjts(dc.m_hDC,(HBITMAP)m_hObject,O,
f¨e.Write(IpBitmap,bmSize):
//cleanuD
(UINT)bi.biHeight,(LPSTR)Ipbi+(WORD)lpbi一>biSize+biColorSize,(LPBITMAPINFO)Ipbi,DIB上GB』OLORS):
//clean
uD
俐e.CIose():
GJobaIUnIock(hD旧):GIobalFree(hDIB):
::GlobaIUnlock(hDIB):、
dc.SelectPaIette(pPaI。FALSE):dc.ReaIizePaIette():
3.在视图中实现绘图,为视类添加一个cwzdBitm印类型
万方数据
爹奠粤警篓囊攀碧粤蹲势、{黼豢囊鬟i
上一篇:2014高考总复习 数列