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
jgui461
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 OriginalGriff 515
1 Maciej Los 349
2 Richard MacCutchan 220
3 BillWoodruff 209
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 28 Mar 2011
Copyright © CodeProject, 1999-2014
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