MFCä¸æä¸ä¸ªä½å¾ç±»CBitmapï¼ä½ å¯å¨èµæºä¸å¯¼å
¥å¾çï¼å¿
é¡»æ¯.bmpæ ¼å¼ï¼ç¶åå®ä¹ç±»ï¼æåBitbltè¿ä¸ªå½æ°å¯ä»¥æä½å¾ä¸è½½å°åææ¡£æè
å
¶å®å·¥ç¨ä¸ç´æ¥æ¾ç¤ºå¾çãä¸é¢æ¯ä¸ä»½èµæï¼ä½ èªå·±ççå§ãå¨Windowsä¸å¯ä»¥å°é¢å
åå¤å¥½çå¾åå¤å¶å°æ¾ç¤ºåºåä¸ï¼è¿ç§å
åæ·è´æ§è¡èµ·æ¥æ¯é常快çãå¨Windowsä¸æä¾äºä¸¤ç§ä½¿ç¨å¾å½¢æ·è´çæ¹æ³ï¼éè¿è®¾å¤ç¸å
³ä½å¾ï¼DDBï¼å设å¤æ å
³ä½å¾ï¼DIBï¼ãDDBå¯ä»¥ç¨MFCä¸çCBitmapæ¥è¡¨ç¤ºï¼èDDBä¸è¬æ¯åå¨å¨èµæºæ件ä¸ï¼å¨å è½½æ¶åªéè¦éè¿èµæºIDå·å°±å¯ä»¥å°å¾å½¢è£
å
¥ãBOOL CBitmap::LoadBitmap( UINT nIDResource )å¯ä»¥è£
å
¥æå®DDBï¼ä½æ¯å¨ç»å¶æ¶å¿
é¡»åå©å¦ä¸ä¸ªåå½åç»å¾DCå
¼å®¹çå
åDCæ¥è¿è¡ãéè¿CDC::BitBlt( int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop )ç»å¶å¾å½¢ï¼åæ¶æå®å
æ
æä½çç±»åãBitBltå¯ä»¥å°æºDCä¸ä½å¾å¤å¶å°ç®çDCä¸ï¼å
¶ä¸åå个åæ°ä¸ºç®çåºåçåæ ï¼æ¥ä¸æ¥æ¯æºDCæéï¼ç¶åæ¯æºDCä¸çèµ·å§åæ ï¼ç±äºBitBlt为çæ¯ä¾å¤å¶ï¼æ以ä¸éè¦å次æå®é¿å®½ï¼ï¼StretchBltå¯ä»¥è¿è¡ç¼©æ¾ï¼æåä¸ä¸ªåæ°ä¸ºå
æ
æä½çç±»åï¼å¯å以ä¸å¼ï¼ BLACKNESS è¾åºåºå为é»è² Turns all output black.DSTINVERT åè²è¾åºåºå Inverts the destination bitmap.MERGECOPY å¨æºåç®çé´ä½¿ç¨ANDæä½ Combines the pattern and the source bitmap using the Boolean AND operator.MERGEPAINT å¨åè²åçç®çåæºé´ä½¿ç¨ORæä½ Combines the inverted source bitmap with the destination bitmap using the Boolean OR operator.NOTSRCCOPY å°åè²åçæºæ·è´å°ç®çåº Copies the inverted source bitmap to the destination.PATINVERT æºåç®çé´è¿è¡XORæä½ Combines the destination bitmap with the pattern using the Boolean XOR operator.SRCAND æºåç®çé´è¿è¡ANDæä½ Combines pixels of the destination and source bitmaps using the Boolean AND operator.SRCCOPY å¤å¶æºå°ç®çåº Copies the source bitmap to the destination bitmap.SRCINVERT æºåç®çé´è¿è¡XORæä½ Combines pixels of the destination and source bitmaps using the Boolean XOR operator.SRCPAINT æºåç®çé´è¿è¡ORæä½ Combines pixels of the destination and source bitmaps using the Boolean OR operator.WHITENESS è¾åºåºå为ç½è² Turns all output white. ä¸é¢ç¨ä»£ç æ¼ç¤ºè¿ç§æ¹æ³ï¼CYourView::OnDraw(CDC* pDC){ CDC memDC;//å®ä¹ä¸ä¸ªå
¼å®¹DC memDC.CreateCompatibleDC(pDC);//å建DC CBitmap bmpDraw; bmpDraw.LoadBitmap(ID_BMP);//è£
å
¥DDB CBitmap* pbmpOld=memDC.SelectObject(&bmpDraw);//ä¿ååæDDBï¼å¹¶éå
¥æ°DDBå
¥DC pDC->BitBlt(0,0,20,20,&memDC,0,0,SRCCOPY);//å°æºDCä¸(0,0,20,20)å¤å¶å°ç®çDC(0,0,20,20) pDC->BitBlt(20,20,40,40,&memDC,0,0,SRCAND);//å°æºDCä¸(0,0,20,20)åç®çDC(20,20,40,40)ä¸åºåè¿è¡ANDæä½ memDC.SelectObject(pbmpOld);//éå
¥åDDB}ï¼å¾æ 并ä¸æ¯ä¸ä¸ªGDI对象ï¼æ以ä¸éè¦éå
¥DCï¼å¨MFCä¸æ²¡æä¸ä¸ªä¸é¨çå¾æ ç±»ï¼å 为å¾æ çæä½æ¯è¾ç®åï¼ä½¿ç¨HICON CWinApp::LoadIcon( UINT nIDResource )ææ¯HICON CWinApp::LoadStandardIcon( LPCTSTR lpszIconName ) è£
å
¥åå°±å¯ä»¥å©ç¨BOOL CDC::DrawIcon( int x, int y, HICON hIcon )ç»å¶ãç±äºå¨å¾æ ä¸å¯ä»¥æå®éæåºåï¼æ以å¨æäºéè¦ä½¿ç¨éè§åå¾å½¢èä¸é¢ç§¯ä¸å¤§çæ¶å使ç¨å¾æ ä¼æ¯è¾ç®åãä¸é¢ç»åºç®åç代ç ï¼ OnDraw(CDC* pDC){ HICON hIcon1=AfxGetApp()->LoadIcon(IDI_I1); HICON hIcon2=AfxGetApp()->LoadIcon(IDI_I2); pDC->DrawIcon(0,0,hIcon1); pDC->DrawIcon(0,40,hIcon2); DestroyIcon(hIcon1); DestroyIcon(hIcon2);}åæ ·å¨MFCä¹æ²¡ææä¾ä¸ä¸ªDIBçç±»ï¼æ以å¨ä½¿ç¨DIBä½å¾æ¶æ们éè¦èªå·±è¯»åä½å¾æ件ä¸ç头信æ¯ï¼å¹¶è¯»å
¥æ°æ®ï¼å¹¶å©ç¨APIå½æ°StretchDIBitsç»å¶ãä½å¾æ件以BITMAPFILEHEADERç»æå¼å§ï¼ç¶åæ¯BITMAPINFOHEADERç»æåè°è²çä¿¡æ¯åæ°æ®ï¼å
¶å®ä½å¾æ ¼å¼æ¯å¾å½¢æ ¼å¼ä¸æç®åçä¸ç§ï¼èä¸ä¹æ¯Windowså¯ä»¥ç解çä¸ç§ãæä¸è¯¦ç»è®²è§£DIBä½å¾çç»æï¼æä¾ä¸ä¸ªCDibç±»ä¾å¤§å®¶ä½¿ç¨ï¼è¿ä¸ªç±»å
å«äºåºæ¬çåè½å¦ï¼Load,Save,DrawãDownLoad
温馨提示:内容为网友见解,仅供参考