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. DIBitmap

DIBitmap

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsdata-structurestutorial
7 Posts 3 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.
  • D Offline
    D Offline
    daojinliu
    wrote on last edited by
    #1

    int the function OnDraw();I want to create a DIB bitmap using the array pData,and display it on the screen,but I am not fail to do it;Would please tell me how to correct the codes below. //the array containing color information unsigned char* pData=new unsigned char[768*576*3]; int y=0, x=0; for(;y<576;y++) for(;x<768;x++) { pData[x*3+y*768*3]=0; pData[x*3+1+y*768*3]=0; pData[x*3+2+y*768*3]=255; } //information header BITMAPINFOHEADER FrameBmi; FrameBmi.biSize=sizeof(BITMAPINFOHEADER); FrameBmi.biPlanes=1; FrameBmi.biCompression=BI_RGB; FrameBmi.biClrImportant=0; FrameBmi.biSizeImage=768*576*3; FrameBmi.biClrUsed=0; FrameBmi.biBitCount=24; FrameBmi.biWidth=768; FrameBmi.biHeight=576; FrameBmi.biXPelsPerMeter = 0; FrameBmi.biYPelsPerMeter =0; //file header BITMAPFILEHEADER pf; pf.bfType=0x4d42; //"BM" pf.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(char[768*576]); pf.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); pf.bfReserved1=0; pf.bfReserved2=0; //BITMAPINFOHEADER LPBITMAPINFO lpbmi=(LPBITMAPINFO)GlobalAlloc(GMEM_FIXED,sizeof(BITMAPINFOHEADER)); ASSERT(lpbmi); lpbmi->bmiHeader.biSize=FrameBmi.biSize; lpbmi->bmiHeader.biPlanes=FrameBmi.biPlanes; lpbmi->bmiHeader.biCompression=FrameBmi.biCompression; lpbmi->bmiHeader.biClrImportant=FrameBmi.biClrImportant; lpbmi->bmiHeader.biSizeImage=FrameBmi.biSizeImage; lpbmi->bmiHeader.biClrUsed=FrameBmi.biClrUsed; lpbmi->bmiHeader.biBitCount=FrameBmi.biBitCount; lpbmi->bmiHeader.biWidth=FrameBmi.biWidth; lpbmi->bmiHeader.biHeight=FrameBmi.biHeight; lpbmi->bmiHeader.biXPelsPerMeter=FrameBmi.biXPelsPerMeter; lpbmi->bmiHeader.biYPelsPerMeter=FrameBmi.biYPelsPerMeter; lpbmi->bmiColors=NULL; //Create DIBitmap CBitmap *OldBitmap; HBITMAP bmp =::CreateDIBitmap((HDC)pDC,&FrameBmi,CBM_INIT,pData,lpbmi, DIB_RGB_COLORS); ASSERT(bmp); // CBitmap bitmap; bitmap.Attach(bmp); CDC dcComp; dcComp.CreateCompatibleDC(pDC); OldBitmap=dcComp.SelectObject(&bitmap); BITMAP bm; bitmap.GetObject(sizeof(BITMAP),&bm); // draw bitmap pDC->BitBlt(0,0,768,576,&dcComp,0,0,SRCCOPY); dcComp.SelectObject(OldBitmap); delete [] pData; GlobalFree(lpbmi); delteDC(dcComp); I LOVE VC -- modified at 6:43 Sunday 16th October, 2005

    C 1 Reply Last reply
    0
    • D daojinliu

      int the function OnDraw();I want to create a DIB bitmap using the array pData,and display it on the screen,but I am not fail to do it;Would please tell me how to correct the codes below. //the array containing color information unsigned char* pData=new unsigned char[768*576*3]; int y=0, x=0; for(;y<576;y++) for(;x<768;x++) { pData[x*3+y*768*3]=0; pData[x*3+1+y*768*3]=0; pData[x*3+2+y*768*3]=255; } //information header BITMAPINFOHEADER FrameBmi; FrameBmi.biSize=sizeof(BITMAPINFOHEADER); FrameBmi.biPlanes=1; FrameBmi.biCompression=BI_RGB; FrameBmi.biClrImportant=0; FrameBmi.biSizeImage=768*576*3; FrameBmi.biClrUsed=0; FrameBmi.biBitCount=24; FrameBmi.biWidth=768; FrameBmi.biHeight=576; FrameBmi.biXPelsPerMeter = 0; FrameBmi.biYPelsPerMeter =0; //file header BITMAPFILEHEADER pf; pf.bfType=0x4d42; //"BM" pf.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(char[768*576]); pf.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); pf.bfReserved1=0; pf.bfReserved2=0; //BITMAPINFOHEADER LPBITMAPINFO lpbmi=(LPBITMAPINFO)GlobalAlloc(GMEM_FIXED,sizeof(BITMAPINFOHEADER)); ASSERT(lpbmi); lpbmi->bmiHeader.biSize=FrameBmi.biSize; lpbmi->bmiHeader.biPlanes=FrameBmi.biPlanes; lpbmi->bmiHeader.biCompression=FrameBmi.biCompression; lpbmi->bmiHeader.biClrImportant=FrameBmi.biClrImportant; lpbmi->bmiHeader.biSizeImage=FrameBmi.biSizeImage; lpbmi->bmiHeader.biClrUsed=FrameBmi.biClrUsed; lpbmi->bmiHeader.biBitCount=FrameBmi.biBitCount; lpbmi->bmiHeader.biWidth=FrameBmi.biWidth; lpbmi->bmiHeader.biHeight=FrameBmi.biHeight; lpbmi->bmiHeader.biXPelsPerMeter=FrameBmi.biXPelsPerMeter; lpbmi->bmiHeader.biYPelsPerMeter=FrameBmi.biYPelsPerMeter; lpbmi->bmiColors=NULL; //Create DIBitmap CBitmap *OldBitmap; HBITMAP bmp =::CreateDIBitmap((HDC)pDC,&FrameBmi,CBM_INIT,pData,lpbmi, DIB_RGB_COLORS); ASSERT(bmp); // CBitmap bitmap; bitmap.Attach(bmp); CDC dcComp; dcComp.CreateCompatibleDC(pDC); OldBitmap=dcComp.SelectObject(&bitmap); BITMAP bm; bitmap.GetObject(sizeof(BITMAP),&bm); // draw bitmap pDC->BitBlt(0,0,768,576,&dcComp,0,0,SRCCOPY); dcComp.SelectObject(OldBitmap); delete [] pData; GlobalFree(lpbmi); delteDC(dcComp); I LOVE VC -- modified at 6:43 Sunday 16th October, 2005

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      daojinliu wrote:

      but I am not successful

      what happens ?? Cleek | Image Toolkits | Thumbnail maker

      D 1 Reply Last reply
      0
      • C Chris Losinger

        daojinliu wrote:

        but I am not successful

        what happens ?? Cleek | Image Toolkits | Thumbnail maker

        D Offline
        D Offline
        daojinliu
        wrote on last edited by
        #3

        I got a error that there was a ASSERT error in the line of "CreateDIBitmap()", I am fail to create a DIB bitmap and display it in the monitor. I LOVE VC

        C PJ ArendsP 2 Replies Last reply
        0
        • D daojinliu

          I got a error that there was a ASSERT error in the line of "CreateDIBitmap()", I am fail to create a DIB bitmap and display it in the monitor. I LOVE VC

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          try calling GetLastError just after CreateDIBitmap Cleek | Image Toolkits | Thumbnail maker

          1 Reply Last reply
          0
          • D daojinliu

            I got a error that there was a ASSERT error in the line of "CreateDIBitmap()", I am fail to create a DIB bitmap and display it in the monitor. I LOVE VC

            PJ ArendsP Offline
            PJ ArendsP Offline
            PJ Arends
            wrote on last edited by
            #5

            pData is too small for the bitmap you are trying to create.


            "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

            Within you lies the power for good; Use it!

            D 1 Reply Last reply
            0
            • PJ ArendsP PJ Arends

              pData is too small for the bitmap you are trying to create.


              "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

              D Offline
              D Offline
              daojinliu
              wrote on last edited by
              #6

              yes,the pData should be pData=new unsigned char[768*576*3],but after above update,I am fail to create the DIB bitmap again, I LOVE VC

              PJ ArendsP 1 Reply Last reply
              0
              • D daojinliu

                yes,the pData should be pData=new unsigned char[768*576*3],but after above update,I am fail to create the DIB bitmap again, I LOVE VC

                PJ ArendsP Offline
                PJ ArendsP Offline
                PJ Arends
                wrote on last edited by
                #7

                ::CreateBitmap(pDC->m_hDC, ...


                "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

                Within you lies the power for good; Use it!

                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