1 / 8

Displaying a Bitmap Image: A Quick Demo

Learn how to create an SDI application in C++ using a bitmap image, with step-by-step instructions and sample code.

tdan
Download Presentation

Displaying a Bitmap Image: A Quick Demo

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. Displaying a BITMAP Image

  3. A Quick Demonstration • Create an SDI application. • In the Resource View, right-click to Add Resource, and create a new Bitmap image. • The default name should be IDB_BITMAP1. • Draw something in the bitmap.

  4. Sample Code • In the OnDraw() function inf the View class, add the following code: • CBitmap Bitmap; • Bitmap.LoadBitmapW(IDB_BITMAP1); • CDC memDC; • memDC.CreateCompatibleDC( pDC ); • memDC.SelectObject( &Bitmap ); • pDC->BitBlt( 0, 0, 48, 48, &memDC, 0, 0, SRCCOPY ); • If Intelli-sense warns you that it does not recognize IDB_BITMAP1 (yet), just ignore the warning. • Build and execute the program.

  5. The meaning of each line of code • A CBitmap object must be declared. • The CBitmap object must be initialized by calling its LoadBitmap() function. • A CDC object must be declared. • The CDC object must be initialized by calling its CreateCompatibleDC() member function. • This DC is referred to as a “memory device context”. • Select the CBitmap object into the CDC object, by calling the CDC’s SelectObject() function. • Copy the memberDC to an on-screen windows, by calling the screen CDC’s BitBlt() function. screen CDC memory DC Bitmap

  6. Can I Load an External Bitmap File? CString szFilename ("Y:\\Waste\\micky.bmp"); HBITMAP hBmp = (HBITMAP)::LoadImageW(NULL, szFilename, IMAGE_BITMAP,0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION); CBitmap Bitmap; // Bitmap.LoadBitmapW(IDB_BITMAP2); Bitmap.Attach(hBmp); CDC memDC; memDC.CreateCompatibleDC( pDC ); CBitmap *pOldbmp = memDC.SelectObject( &Bitmap ); BITMAP bi;// Get the BMP Height and Width Bitmap.GetBitmap(&bi); pDC->BitBlt( 0, 0, bi.bmWidth, bi.bmHeight, &memDC, 0, 0, SRCCOPY ); memDC.SelectObject( pOldbmp );

  7. Add a Button to Trigger the Action • Create an SDI (single document interface) application. • Select CFormView as the base class. • In the Resource View, expand the Dialog resource and double-click the form. • Drag a button control to the form. • Double-click the button to add a handler. • Insert the code for displaying a BITMAP file.

  8. HW21 • Design an application with 3 buttons. Each button will display a different bitmap file when it is pushed. • Bonus: Design your button so that it will show/hide the corresponding bitmap as a toggle switch.

More Related