Hi,
has someone an idea on how to use GdipBitmapLockBits right to get pixels from Windows pictures with GDI+?
Greetings
Christian
Hi,
has someone an idea on how to use GdipBitmapLockBits right to get pixels from Windows pictures with GDI+?
Greetings
Christian
See my (possibly) related question here: https://forum.xojo.com/13042-picture-copyoshandle-on-win32-with-32-bit-pictures
I wonder if the object that’s begin returned by Xojo is not a GDI+ bitmap, but just a regular BITMAP object?
my code looks like this:
[code] REALpictureDescription des;
if (REALLockPictureDescriptionX(pic, &des, pictureGDIPlusBitmap))
{
DebugMessage(“pictureGDIPlusBitmap”);
RBInteger w = des.width;
RBInteger h = des.height;
DebugMessage("w",w);
DebugMessage("h",h);
if (des.pictureType == pictureGDIPlusBitmap)
{
GpBitmap* g = (GpBitmap*) des.pictureData;
DebugMessage("g",g);
if (g)
{
if (LoadGDIPlus())
{
BitmapData* bitmapData = new BitmapData();
DebugMessage("bitmapData", (void*)bitmapData);
if (bitmapData )
{
RBInteger flags = ImageLockModeRead|ImageLockModeWrite;
DebugMessage("flags",flags);
GpRect r;
r.left = 0;
r.top = 0;
r.right = w;
r.bottom = h;
GpStatus e = _GdipBitmapLockBits(g, &r, flags, PixelFormat32bppPARGB, bitmapData);
DebugMessage("e",e);
if (e == 2)
{
e = _GdipBitmapLockBits(g, &r, flags, PixelFormat32bppARGB, bitmapData);
DebugMessage("e",e);
}
if (e != Ok)
{
DebugMessage("Lockbits failed");
delete bitmapData;
REALUnlockPictureDescription(pic);
return;
}
[/code]
from debug output I see that I got a GpBitmap with right pixel size.
Pixel format is PixelFormat32bppRGB and type is a ImageTypeBitmap.
passing rectangle was wrong! Passing NULL works
I’m confused about the Rectangle here - in the Win32API we have
typedef struct _RECT {
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT;
but I also see places where gpRect is defined as { X,Y,width,height }.
The difference of course would be that right = X+width and bottom = Y + height?
Could you be passing a pointer to the wrong structure type?
[quote=101209:@Michael Diehr]I’m confused about the Rectangle here - in the Win32API we have
typedef struct _RECT {
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT;
but I also see places where gpRect is defined as { X,Y,width,height }.
The difference of course would be that right = X+width and bottom = Y + height?
Could you be passing a pointer to the wrong structure type?[/quote]
EDIT: no, I think you are correct, here’s where Rect is defined (which is not the same as RECT): http://msdn.microsoft.com/en-us/library/windows/desktop/ms534495(v=vs.85).aspx
for me it started working when I stopped passing a rect at all!
Have you tried passing in a buffer for the pixels and then using the imageLockModeUserInputBuf = &h0004 flag?
no