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. How to convert CBitmap to DIB and backwards

How to convert CBitmap to DIB and backwards

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structureshelptutorial
5 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.
  • U Offline
    U Offline
    uus99
    wrote on last edited by
    #1

    I have a 32 bit (RGBA) image in CBitmap, and for processing purposes i get the array using GetBitmapBits & SetBitmapBits. And after that plot to screen. The problem is that is only works if the target system is also running on 32bit screen depth. How can i get an array of pixel values from CBitmap to a DIB then after processing plot to screen? Also, any DIB class? I'm completely lost.

    C J 2 Replies Last reply
    0
    • U uus99

      I have a 32 bit (RGBA) image in CBitmap, and for processing purposes i get the array using GetBitmapBits & SetBitmapBits. And after that plot to screen. The problem is that is only works if the target system is also running on 32bit screen depth. How can i get an array of pixel values from CBitmap to a DIB then after processing plot to screen? Also, any DIB class? I'm completely lost.

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

      uus99 wrote: The problem is that is only works if the target system is also running on 32bit screen depth why doesn't it work on other bit depths? what happens? Cleek | Losinger Designs | ClickPic | ThumbNailer

      1 Reply Last reply
      0
      • U uus99

        I have a 32 bit (RGBA) image in CBitmap, and for processing purposes i get the array using GetBitmapBits & SetBitmapBits. And after that plot to screen. The problem is that is only works if the target system is also running on 32bit screen depth. How can i get an array of pixel values from CBitmap to a DIB then after processing plot to screen? Also, any DIB class? I'm completely lost.

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        RGBA: sounds like you are using GDI+. In which case look up GDI+ here at CP, there are several aticles on working with bitmaps. Also, check out Bitmaps & Palettes: CxImage, CDIBSection, CDibData uses GDI and sould give you an insight on converting from one format to anouther if needed. Using GetBitampBits and SetBitmapBits is not garanteed to give you the bits in any given format; therefore, they could eventualy return/set bits using a different format (driver dependent). Well I hope this helps. Good Luck! INTP

        U 1 Reply Last reply
        0
        • J John R Shaw

          RGBA: sounds like you are using GDI+. In which case look up GDI+ here at CP, there are several aticles on working with bitmaps. Also, check out Bitmaps & Palettes: CxImage, CDIBSection, CDibData uses GDI and sould give you an insight on converting from one format to anouther if needed. Using GetBitampBits and SetBitmapBits is not garanteed to give you the bits in any given format; therefore, they could eventualy return/set bits using a different format (driver dependent). Well I hope this helps. Good Luck! INTP

          U Offline
          U Offline
          uus99
          wrote on last edited by
          #4

          The thing is i am receiving an image from a frame grabber in MemDC, which the image is RGBA (32bits) and tha A=0 all the times, so actually it is RGB (24bits+8bits empty). At the moment, i can plot to screen using pDC->StretchBlt(20,40,180,180,&MemDC,10,40,512,512,SRCCOPY); It works, coz my screen is on 32bit depth. If my screen is changed to 24bit or 16bit, nothing comes out. So, how can i make sure that i can always plot to any screen depth? I should use DIB is it?

          J 1 Reply Last reply
          0
          • U uus99

            The thing is i am receiving an image from a frame grabber in MemDC, which the image is RGBA (32bits) and tha A=0 all the times, so actually it is RGB (24bits+8bits empty). At the moment, i can plot to screen using pDC->StretchBlt(20,40,180,180,&MemDC,10,40,512,512,SRCCOPY); It works, coz my screen is on 32bit depth. If my screen is changed to 24bit or 16bit, nothing comes out. So, how can i make sure that i can always plot to any screen depth? I should use DIB is it?

            J Offline
            J Offline
            John R Shaw
            wrote on last edited by
            #5

            Sorry I have be gone for a few days. It almost sounds like the MemDC and the pDC are incompatible, because the color depth of the bitmap should not be the problem. If you select a bitmap of higher resolution than the screen and then blit it to the screen all you should notice, if any thing, is that the colors appear wrong. The only reason (normaly) for using a DIB, insted of a the normal windows bitmap type, is when you need to access the bits directly (more efficeintly). I do no beleive using a DIB will fix the problem. If you do not have a copy of Programming Windows by Charles Petzold, then I recommend you get one, it provides good information on GDI as well as code for working with DIBs. The bit manipulation code in CDibData was based mosly on information from that book. Good Luck! P.S. if you figure out what the problem is, please post it. INTP

            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