使用GDI位元影像

來源:互聯網
上載者:User

  GDI位元影像只是另一個GDI對象,例如筆或者字型。你必須先建立一個位元影像,然後將它選入裝置環境。當你完成改對象的操作之後,必須解除對它的選中,並刪除它。

儘管如此,仍有一些問題,原因是顯示器的“位元影像”實際上就是顯示器表面映像,印表機裝置的“位元影像”是列印頁面本身。因此不能將位元影像選入顯示裝置環境或者印表機裝置環境。必須使用CDC::CreateCompatibleDC 函數為位元影像建立一個特殊的記憶體裝置環境。然後使用CDC::StretchBlt或者CDC::BitBlt來從記憶體裝置環境中向"真正"的裝置環境中複製這些位。

範例:

void CBlat2View::OnDraw(CDC* pDC){   CBlat2Doc* pDoc = GetDocument();   ASSERT_VALID(pDoc);   // load IDB_BITMAP1 from our resources   CBitmap bmp;   if (bmp.LoadBitmap(IDB_BITMAP1))   {      // Get the size of the bitmap      BITMAP bmpInfo;      bmp.GetBitmap(&bmpInfo);      // Create an in-memory DC compatible with the      // display DC we're using to paint      CDC dcMemory;      dcMemory.CreateCompatibleDC(pDC);      // Select the bitmap into the in-memory DC      CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);      // Find a centerpoint for the bitmap in the client area      CRect rect;      GetClientRect(&rect);      int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;      int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;      // Copy the bits from the in-memory DC into the on-      // screen DC to actually do the painting. Use the centerpoint      // we computed for the target offset.      pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,          0, 0, SRCCOPY);      dcMemory.SelectObject(pOldBitmap);   }   else      TRACE0("ERROR: Where's IDB_BITMAP1?\n");}

顯示映射模式:MM_TEXT 每個位元影像像素將映射為一個顯示像素。

                          MM_LOENGLISH :位元影像大小將是 0.54*0.96 英寸。

 

注 GDI對象包括:Cbitmap, CBrush,CFont, CPalette,CPen,CRgn。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.