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. CBitmap vs. HBITMAP

CBitmap vs. HBITMAP

Scheduled Pinned Locked Moved C / C++ / MFC
learningc++visual-studiographicsjson
3 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.
  • C Offline
    C Offline
    CoY0te
    wrote on last edited by
    #1

    How to ensure that CBitmap object will be created with 24bpp and it will stay that way when I use LoadBitmap? In typical API I would use the CreateDIBSection to create a 24bpp bitmap and I could freely access it's bits. But there is no such function in MFC. Do I have to use these API functions, or is there any "nice" way to do that with MFC classes? Some additional information: My code goes like this: CPoint Point; CBitmap Bitmap; Bitmap.LoadBitmap(IDB_BITMAP); Then I use my own function that converts colors in 24bpp images: ConvertBitmapColors(Bitmap); And I draw it on the screen; dc.DrawState(Point,Bitmap.GetBitmapDimension(),&Bitmap,DST_BITMAP | DSS_NORMAL); (dc is of course a CPaintDC object) Finally: Bitmap.DeleteObject(); The IDB_BITMAP resource is 24bpp bitmap, but the Bitmap object loads it with current desktop's color depth. I need some way to have an 24bpp bitmap, cause I want to make that color conversion before I draw it. [ CoY0te ] Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.

    C 1 Reply Last reply
    0
    • C CoY0te

      How to ensure that CBitmap object will be created with 24bpp and it will stay that way when I use LoadBitmap? In typical API I would use the CreateDIBSection to create a 24bpp bitmap and I could freely access it's bits. But there is no such function in MFC. Do I have to use these API functions, or is there any "nice" way to do that with MFC classes? Some additional information: My code goes like this: CPoint Point; CBitmap Bitmap; Bitmap.LoadBitmap(IDB_BITMAP); Then I use my own function that converts colors in 24bpp images: ConvertBitmapColors(Bitmap); And I draw it on the screen; dc.DrawState(Point,Bitmap.GetBitmapDimension(),&Bitmap,DST_BITMAP | DSS_NORMAL); (dc is of course a CPaintDC object) Finally: Bitmap.DeleteObject(); The IDB_BITMAP resource is 24bpp bitmap, but the Bitmap object loads it with current desktop's color depth. I need some way to have an 24bpp bitmap, cause I want to make that color conversion before I draw it. [ CoY0te ] Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.

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

      I have solved that problem by coding my conversion this way: CDC * pdc; CBitmap * OldBitmap; pdc=new CDC; pdc->CreateCompatibleDC(NULL); OldBitmap=pdc->SelectObject(Target); //this part of code is looped pdc->GetPixel(Point) ... //Color conversion ... pdc->SetPixelV(Point,Color) pdc->SelectObject(OldBitmap); pdc->DeleteDC(); delete pdc; It works allright, but only because these images are small (9x15). Using GetPixel / SetPixelV is kinda slow i guess. It would be better to have a direct access to 24bpp image, but I haven't figured out how to load a resource into CBitmap object as 24bpp image every time. If someone has any better idea to do it faster without writting a bunch of code, then let me know please. Greetings. [ CoY0te ] Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.

      E 1 Reply Last reply
      0
      • C CoY0te

        I have solved that problem by coding my conversion this way: CDC * pdc; CBitmap * OldBitmap; pdc=new CDC; pdc->CreateCompatibleDC(NULL); OldBitmap=pdc->SelectObject(Target); //this part of code is looped pdc->GetPixel(Point) ... //Color conversion ... pdc->SetPixelV(Point,Color) pdc->SelectObject(OldBitmap); pdc->DeleteDC(); delete pdc; It works allright, but only because these images are small (9x15). Using GetPixel / SetPixelV is kinda slow i guess. It would be better to have a direct access to 24bpp image, but I haven't figured out how to load a resource into CBitmap object as 24bpp image every time. If someone has any better idea to do it faster without writting a bunch of code, then let me know please. Greetings. [ CoY0te ] Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.

        E Offline
        E Offline
        Ernest Laurentin
        wrote on last edited by
        #3

        Did you look at Chris's DibSection class? As my daughter would say, "... Whatever!"

        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