CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 1 of 1
  1. #1
    Join Date
    Apr 2011

    Question Difference between SetDIBitsToDevice() and BitBlt()?


    I wanted to display a bitmap data within a Picture Control. For that, I implemented the visualization on the one hand by means of <b>setDIBitsToDevice()</b>, where the image data in array is displayed usind the device context (DV) of the picture control directly, and on the other hand by creating a second device context, assigning a created DIbitmap to it and transfering the data from second DC to the first one:

    // create a mirror device context associated with the target device context
    HDC hdcCreated = ::CreateCompatibleDC(hdc);
    // create a bitmap, which will be selected together with the defined device context
    HBITMAP bmCreated = ::CreateDIBitmap(hdc, (BITMAPINFOHEADER*)&(BmInfo.bmiHeader), CBM_INIT , (VOID*)myImageArray, &BmInfo, DIB_RGB_COLORS );		
    // connect the bitmap with the mirror device context
    HBITMAP hBmOld = (HBITMAP) ::SelectObject(hdcCreated, bmCreated);
    // transfer the bitmap data from the mirror device context to the target DC
    //::BitBlt(hdc,0,0, m_nSizeX, m_nSizeY, hdcCreated, 0, 0, SRCCOPY);
    // delete created bitmaps and DC, if not used anymore
    Both methods are working fine, but I wonder why there are two methods for the same purpose? I watched the CPU load for each method to see, whether they differ in performance. However, they don't differ.

    Can you tell me please, in which cases should the first method and in which the second method be used?

    Thank you
    Last edited by vanselm; May 5th, 2011 at 09:41 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width