CBitmap vs. HBITMAP
-
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. -
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.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. -
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.Did you look at Chris's DibSection class? As my daughter would say, "... Whatever!"