Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
In the following article:
Finding a Bitmap contained inside another Bitmap

There is GDI+ method to load bitmap before use of LockBits funtion. We ant to use only PixelFormat24bppRGB because then we want LockBits to determine pixels of bitmap. It works pretty well, when we use .bmp image as source. But when I try to use another format, this is not working at all.

I tried to load .jpg with GDI+ and then to make a clone with only PixelFormat24bppRGB.
With no success.
C++
Gdiplus::Bitmap* bm = new Bitmap(L"test.jpg");
Gdiplus::Bitmap* bigBmp = bm->Clone(0, 0, bm->GetWidth(), bm->GetHeight(), PixelFormat24bppRGB);
Gdiplus::BitmapData* bigbitmapData = new BitmapData;
Gdiplus::Rect bigRect(0, 0, bigBmp->GetWidth(), bigBmp->GetHeight());
bigBmp->LockBits(&bigRect, ImageLockModeRead, PixelFormat24bppRGB, bigbitmapData);

the bitmap from jpg is loaded correctly because I got correct width and height.

When I use in the above code:
C++
Gdiplus::Bitmap* bm = new Bitmap(L"test.bmp");

(where .bmp I tested both 24-bits colors and 16 and 8-bits) everything is working fine.

I guess the problem is becasue of colors number in .jpg

How to fix .jpg for PixelFormat24bppRGB? Any idea? please.
Posted
Updated 28-Mar-11 0:01am
v2

1 solution

correction:

this problem is for JPEG only.

both .bmp and .png and .tif file formats are working correctly.

with any colors format.

.png 24-bits colors and the reduced to 256 colors are working fine.

maybe the problem is not in LockBits function, but with the next part of code?

where we calculate pixels luminance to find inside the bitmap.
(see the above article)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900