Click here to Skip to main content
13,054,779 members (72,120 online)
Rate this:
Please Sign up or sign in to 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.
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:
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 27-Mar-11 22:46pm
Updated 28-Mar-11 0:01am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 28 Mar 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100