Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: GDI+
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 23:46pm
jgui464
Edited 28-Mar-11 1:01am
v2

1 solution

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

Solution 1

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)
  Permalink  

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

  Print Answers RSS
0 Maciej Los 199
1 Sergey Alexandrovich Kryukov 154
2 Sascha Lefévre 120
3 Abhinav S 104
4 Rana Waqas 78
0 Sergey Alexandrovich Kryukov 6,628
1 OriginalGriff 6,298
2 Peter Leow 2,534
3 Maciej Los 2,437
4 Abhinav S 2,378


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 28 Mar 2011
Copyright © CodeProject, 1999-2015
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