1 / 15

位图的显示

位图的显示. 实验四. 为应用程序制作一个封面窗口 , 在应用程序主窗口显示之前首先弹出封面窗口 , 窗口显示一个位图 ,5 秒钟后该窗口自动关闭 , 主窗口被打开。. CBitmap. 封装了 GDI 位图 bitmap 和对位图的各种操作 CBitmap::GetBitmap int GetBitmap( BITMAP* pBitMap BITMAP Structure { int bmType; int bmWidth; int bmHeight; int bmWidthBytes;

hachi
Download Presentation

位图的显示

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 位图的显示

  2. 实验四 • 为应用程序制作一个封面窗口,在应用程序主窗口显示之前首先弹出封面窗口,窗口显示一个位图,5秒钟后该窗口自动关闭,主窗口被打开。

  3. CBitmap • 封装了GDI位图bitmap和对位图的各种操作 • CBitmap::GetBitmap int GetBitmap( BITMAP* pBitMap • BITMAP Structure{ int bmType; int bmWidth; int bmHeight; int bmWidthBytes; BYTE bmPlanes; BYTE bmBitsPixel; LPVOID bmBits; }

  4. CBitmap::LoadBitmap • BOOLLoadBitmap(UINTnIDResource); 装载位图资源,建立位图对象

  5. 内存DC • 内存DC是代表DC的一个内存块,经常用来准备在窗口DC上显示的位图 • CDC::CreateCompatibleDC virtualBOOLCreateCompatibleDC(CDC*pDC); 创建与pDC兼容的内存DC

  6. CDC::BitBlt 从内存dc拷贝位图 BOOLBitBlt( intx, inty, //目标DC中的起始点 intnWidth,intnHeight, //目标矩形和位图尺寸 CDC*pSrcDC, //源DC intxSrc,intySrc, //源DC中的起始点 DWORDdwRop);

  7. 三重光栅操作(源位图S、画刷P、目标位图D)Ternary Raster Operations SRCCOPY D=S SRCAND D=S AND D NOTSRCCOPYD=NOT S BLACKNESS D=BLCAK SRCPAINT D=S OR D MERGECOPY D=S OR P …

  8. CDC::StretchBlt 从内存DC拷贝位图,并作伸缩处理 BOOLStretchBlt( intx,inty, intnWidth,intnHeight, //目标dc的矩形区 CDC*pSrcDC, intxSrc,intySrc, intnSrcWidth,intnSrcHeight, //源dc的矩形区 DWORDdwRop);

  9. CDC::SetStretchBltMode • intSetStretchBltMode(intnStretchMode); • BLACKONWHITE • WHITEONBLACK //用于黑白位图 • COLORONCOLOR //用于彩色位图

  10. 在窗口显示位图 • 创建CBitmap 对象,并装载位图资源 CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP1)) • 获取位图信息(大小) BITMAP bmpInfo; bmp.GetBitmap(&bmpInfo);

  11. 创建与显示DC兼容的内存DC CDC dcMemory; dcMemory.CreateCompatibleDC(pDC); • 将CBitmap对象选入内存DC CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp); • 调用BitBlt或StrechBlt函数将内存DC的位图拷贝到窗口DC显示 pDC->SetStretchBltMode(COLORONCOLOR); pDC->StretchBlt(0, 0, rect.Width(), rect.Height(), &dcMemory, 0, 0,bmpInfo.bmWidth, bmpInfo.bmHeight, MERGECOPY );

  12. 裁剪区属性的使用

  13. CRgn BOOLCreateRectRgn(intx1,inty1,intx2,inty2); BOOLCreateEllipticRgn(intx1,inty1,intx2,inty2); BOOLCreatePolygonRgn(LPPOINTlpPoints,intnCount,intnMode);

  14. CDC::SelectClipRgn • virtualintSelectClipRgn(CRgn*pRgn); • intSelectClipRgn(CRgn*pRgn,intnMode);

  15. Example: CRgn rgn1,rgn2,rgn3; rgn1.CreateEllipticRgn( rect.left,rect.top,rect.right,rect.bottom); rgn2.CreateRectRgn(rect.left,rect.top,rect.right,rect.bottom); rgn2.CombineRgn(&rgn1,&rgn2,RGN_XOR); pDC->SelectClipRgn(&rgn2);

More Related