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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Conversion of CBitmap into Array of BYTE and Vice Versa

Conversion of CBitmap into Array of BYTE and Vice Versa

Scheduled Pinned Locked Moved C / C++ / MFC
sysadmindata-structures
5 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.
  • M Offline
    M Offline
    Madhu_Rani
    wrote on last edited by
    #1

    Hi, I had a simple client/server application that excahnges text data through array of bytes (BYTE byBuffer[256]). Now the server wants to transmit the image data (CBitmap) to the client. How the CBitmap object can be converted into array of bytes and then on receiving end (client) it can be converted back into CBitmap. THANKS.

    A 1 Reply Last reply
    0
    • M Madhu_Rani

      Hi, I had a simple client/server application that excahnges text data through array of bytes (BYTE byBuffer[256]). Now the server wants to transmit the image data (CBitmap) to the client. How the CBitmap object can be converted into array of bytes and then on receiving end (client) it can be converted back into CBitmap. THANKS.

      A Offline
      A Offline
      Adam Roderick J
      wrote on last edited by
      #2

      To get the CBitmap to byte use GetBitmap( BITMAP* pBitMap ); refer http://msdn.microsoft.com/en-us/library/279a3c0c(VS.80).aspx[^] of CBitmap where LPVOID bmBits member of BITMAP will having the byte array. To set the BYTE array to CBitmap, you can use DWORD SetBitmapBits( DWORD dwCount, const void* lpBits ); you can set your byte array to lpBits. :)

      Величие не Бога может быть недооценена.

      M 1 Reply Last reply
      0
      • A Adam Roderick J

        To get the CBitmap to byte use GetBitmap( BITMAP* pBitMap ); refer http://msdn.microsoft.com/en-us/library/279a3c0c(VS.80).aspx[^] of CBitmap where LPVOID bmBits member of BITMAP will having the byte array. To set the BYTE array to CBitmap, you can use DWORD SetBitmapBits( DWORD dwCount, const void* lpBits ); you can set your byte array to lpBits. :)

        Величие не Бога может быть недооценена.

        M Offline
        M Offline
        Madhu_Rani
        wrote on last edited by
        #3

        Thanks. I am facing problems with GetBitmap , however GetBitmapBits is giving me byte of array properly.( I guess). but I am unable to get the size of these bits for SetBitmapBits( DWORD dwCount, const void* lpBits ).

        A 1 Reply Last reply
        0
        • M Madhu_Rani

          Thanks. I am facing problems with GetBitmap , however GetBitmapBits is giving me byte of array properly.( I guess). but I am unable to get the size of these bits for SetBitmapBits( DWORD dwCount, const void* lpBits ).

          A Offline
          A Offline
          Adam Roderick J
          wrote on last edited by
          #4

          you getting any error in GetBitmapBits? r u not getting the size?

          Величие не Бога может быть недооценена.

          M 1 Reply Last reply
          0
          • A Adam Roderick J

            you getting any error in GetBitmapBits? r u not getting the size?

            Величие не Бога может быть недооценена.

            M Offline
            M Offline
            Madhu_Rani
            wrote on last edited by
            #5

            I tried with the way discussed in the article as well. Using GetBitmapBits and SetBitmapBits[^] but it does not work. There is no error but the output is not correct. see the code below CDeskTop desktop; BITMAP bmpX,bmpY; CBitmap mybmp,bmpClone; DWORD dwValue,dwValue2; mybmp.Attach(desktop.GetDeskTopImage()); mybmp.GetBitmap(&bmpX ); bmpClone.LoadBitmap(IDB_BITMAP1); // IDB_BITMAP1 bears the same co-ordinate as the source int x=bmpX.bmHeight*bmpX.bmWidth; BYTE* bmpBuffer=NULL; bmpBuffer=(BYTE*)GlobalAlloc(GMEM_ZEROINIT,bmpX.bmWidth*bmpX.bmHeight); dwValue=mybmp.GetBitmapBits(bmpX.bmWidth*bmpX.bmHeight,bmpBuffer); dwValue2 = bmpClone.SetBitmapBits(bmpX.bmWidth*bmpX.bmHeight,bmpBuffer); bmpClone.GetBitmap(&bmpY); CDC memDC; CClientDC dc(this); memDC.CreateCompatibleDC(&dc); memDC.SelectObject(&bmpClone ); dc.BitBlt(0, 0, bmpY.bmWidth, bmpY.bmHeight, &memDC, 0, 0,SRCCOPY); DeleteDC(dc.m_hDC); GlobalFree((HGLOBAL)bmpBuffer);

            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