Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A query in bitmap routine

A query in bitmap routine

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasegraphicsdebugging
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jossion
    wrote on last edited by
    #1

    Below is the code snippet I wrote for displaying pixel values onto the screen in MFC. The pixel values are stored in buffer disp_frame. But nothing appears on screen. Could anyone debug this code. void CBluetooth_decoderDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default int p=0,i=0,j=0,q=0; // extern int disp_frame[50][144][176]; /////////////////////// BITMAPINFOHEADER bmi; BITMAPINFO bm; RGBQUAD rgbarray[256]; bmi.biSize = sizeof(BITMAPINFOHEADER); bmi.biWidth = 176; bmi.biHeight = 144; bmi.biPlanes = 1; bmi.biBitCount = 8; bmi.biCompression = BI_RGB; bmi.biSizeImage = 0; bmi.biXPelsPerMeter = 0; bmi.biYPelsPerMeter = 0; bmi.biClrUsed = 0; bmi.biClrImportant = 0; bm.bmiHeader = bmi; for (int color_index = 0; color_index < 256; color_index++) { rgbarray[color_index].rgbBlue = i; rgbarray[color_index].rgbGreen = i; rgbarray[color_index].rgbRed = i; rgbarray[color_index].rgbReserved = 0; } bm.bmiColors[1] = rgbarray[0]; ///////////////////// CRect rcClient; GetClientRect(rcClient); // See Note 1 rcClient.right=176; rcClient.bottom=144; CDC MemDC,*pDC; CBitmap MemBitmap,*drawmem; pDC = this->GetDC(); // Get Current DC MemDC.CreateCompatibleDC(pDC); CreateDIBSection(MemDC,bm,DIB_RGB_COLORS,disp_frame,NULL,0); CBitmap *pOldBitmap =MemDC.SelectObject(&MemBitmap); pDC->BitBlt(150,100,176,144,&MemDC,0,0,SRCCOPY); MemDC.SelectObject(pOldBitmap); ReleaseDC(pDC); }

    C 1 Reply Last reply
    0
    • J jossion

      Below is the code snippet I wrote for displaying pixel values onto the screen in MFC. The pixel values are stored in buffer disp_frame. But nothing appears on screen. Could anyone debug this code. void CBluetooth_decoderDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default int p=0,i=0,j=0,q=0; // extern int disp_frame[50][144][176]; /////////////////////// BITMAPINFOHEADER bmi; BITMAPINFO bm; RGBQUAD rgbarray[256]; bmi.biSize = sizeof(BITMAPINFOHEADER); bmi.biWidth = 176; bmi.biHeight = 144; bmi.biPlanes = 1; bmi.biBitCount = 8; bmi.biCompression = BI_RGB; bmi.biSizeImage = 0; bmi.biXPelsPerMeter = 0; bmi.biYPelsPerMeter = 0; bmi.biClrUsed = 0; bmi.biClrImportant = 0; bm.bmiHeader = bmi; for (int color_index = 0; color_index < 256; color_index++) { rgbarray[color_index].rgbBlue = i; rgbarray[color_index].rgbGreen = i; rgbarray[color_index].rgbRed = i; rgbarray[color_index].rgbReserved = 0; } bm.bmiColors[1] = rgbarray[0]; ///////////////////// CRect rcClient; GetClientRect(rcClient); // See Note 1 rcClient.right=176; rcClient.bottom=144; CDC MemDC,*pDC; CBitmap MemBitmap,*drawmem; pDC = this->GetDC(); // Get Current DC MemDC.CreateCompatibleDC(pDC); CreateDIBSection(MemDC,bm,DIB_RGB_COLORS,disp_frame,NULL,0); CBitmap *pOldBitmap =MemDC.SelectObject(&MemBitmap); pDC->BitBlt(150,100,176,144,&MemDC,0,0,SRCCOPY); MemDC.SelectObject(pOldBitmap); ReleaseDC(pDC); }

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Have a look at CreateDIBSection documentation [^]. It states the 5th parameter (a pointer to a pointer) is an [out] one. It means you have to pass the address of a pointer and, on return, that pointer will contain the address of the allocated DIB section buffer, then you have to change the bit values of such buffer, according to disp_frame values, before selecting it into device context. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      J 1 Reply Last reply
      0
      • C CPallini

        Have a look at CreateDIBSection documentation [^]. It states the 5th parameter (a pointer to a pointer) is an [out] one. It means you have to pass the address of a pointer and, on return, that pointer will contain the address of the allocated DIB section buffer, then you have to change the bit values of such buffer, according to disp_frame values, before selecting it into device context. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

        J Offline
        J Offline
        jossion
        wrote on last edited by
        #3

        rtant = 0; bm.bmiHeader = bmi; for (int color_index = 0; color_index < 256; color_index++) { rgbarray[color_index].rgbBlue = i; rgbarray[color_index].rgbGreen = i; rgbarray[color_index].rgbRed = i; rgbarray[color_index].rgbReserved = 0; } bm.bmiColors[1] = rgbarray[0]; ///////////////////// CRect rcClient; GetClientRect(rcClient); // See Note 1 rcClient.right=176; rcClient.bottom=144; CDC MemDC,*pDC; CBitmap MemBitmap,*drawmem; pDC = this->GetDC(); // Get Current DC MemDC.CreateCompatibleDC(pDC); CreateDIBSection(MemDC,bm,DIB_RGB_COLORS,disp_frame,NULL,0); CBitmap *pOldBitmap =MemDC.SelectObject(&MemBitmap); pDC->BitBlt(150,100,176,144,&MemDC,0,0,SRCCOPY); MemDC.SelectObject(pOldBitmap); ReleaseDC(pDC); } This was the piece of code which was posted previously. But the CreateDIBSection code CreateDIBSection(MemDC,bm,DIB_RGB_COLORS,disp_frame,NULL,0); was having MemDC is a CDC type. But actually it should be HDC type. So I have rewritten the code as HDC hDC; hDC = CreateDC("DISPLAY",NULL,NULL,NULL); HDC memDC = CreateCompatibleDC(hDC); CreateDIBSection(hDC,bitmap,DIB_PAL_COLORS,ppbits,NULL,0); HBITMAP memBM = CreateCompatibleBitmap(hDC,176,144); SelectObject(memDC,memBM); BitBlt(memDC,150,100,176,144,hDC,0,0,SRCCOPY); But CreateDIBSection is creating exception. What could be the reason. Basically I could not get the difference between CDC and HDC. Could anyone give a clear solution to my problem. I am actually trying to display a grayscale image which exists as R=G=B values in memory.

        C 1 Reply Last reply
        0
        • J jossion

          rtant = 0; bm.bmiHeader = bmi; for (int color_index = 0; color_index < 256; color_index++) { rgbarray[color_index].rgbBlue = i; rgbarray[color_index].rgbGreen = i; rgbarray[color_index].rgbRed = i; rgbarray[color_index].rgbReserved = 0; } bm.bmiColors[1] = rgbarray[0]; ///////////////////// CRect rcClient; GetClientRect(rcClient); // See Note 1 rcClient.right=176; rcClient.bottom=144; CDC MemDC,*pDC; CBitmap MemBitmap,*drawmem; pDC = this->GetDC(); // Get Current DC MemDC.CreateCompatibleDC(pDC); CreateDIBSection(MemDC,bm,DIB_RGB_COLORS,disp_frame,NULL,0); CBitmap *pOldBitmap =MemDC.SelectObject(&MemBitmap); pDC->BitBlt(150,100,176,144,&MemDC,0,0,SRCCOPY); MemDC.SelectObject(pOldBitmap); ReleaseDC(pDC); } This was the piece of code which was posted previously. But the CreateDIBSection code CreateDIBSection(MemDC,bm,DIB_RGB_COLORS,disp_frame,NULL,0); was having MemDC is a CDC type. But actually it should be HDC type. So I have rewritten the code as HDC hDC; hDC = CreateDC("DISPLAY",NULL,NULL,NULL); HDC memDC = CreateCompatibleDC(hDC); CreateDIBSection(hDC,bitmap,DIB_PAL_COLORS,ppbits,NULL,0); HBITMAP memBM = CreateCompatibleBitmap(hDC,176,144); SelectObject(memDC,memBM); BitBlt(memDC,150,100,176,144,hDC,0,0,SRCCOPY); But CreateDIBSection is creating exception. What could be the reason. Basically I could not get the difference between CDC and HDC. Could anyone give a clear solution to my problem. I am actually trying to display a grayscale image which exists as R=G=B values in memory.

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          Please surround code snippets with <pre> tags. (1) What error message are you receiving? (2) how did you define ppbits?

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          J 1 Reply Last reply
          0
          • C CPallini

            Please surround code snippets with <pre> tags. (1) What error message are you receiving? (2) how did you define ppbits?

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            J Offline
            J Offline
            jossion
            wrote on last edited by
            #5

            The error message was Unhandled exception in decoder.exe(GDI32.dll): 0xc0000005 : Access Violation the declaration for ppbits was void **ppbits. Once this CreateDIBSection works i thought of filling ppbits with pixel values. That's why that particular piece of code is not available

            C 1 Reply Last reply
            0
            • J jossion

              The error message was Unhandled exception in decoder.exe(GDI32.dll): 0xc0000005 : Access Violation the declaration for ppbits was void **ppbits. Once this CreateDIBSection works i thought of filling ppbits with pixel values. That's why that particular piece of code is not available

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              jossion wrote:

              the declaration for ppbits was void **ppbits

              The above is wrong. You have to declare a pointer to void, for instance

              void * pbits;

              and then pass the address of the pointer (i.e. &pbits) to CreateDIBSection:

              CreateDIBSection(hDC,bitmap,DIB_PAL_COLORS, &pbits, NULL,0);

              :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups