Hello!
I am trying to port an application from windows, where I have a pointer to bitmap data in BGR24 format (default windows DIB).
In windows I do:
procedure display(pData: Pointer);
var
b: TBitmap;
bi: TBitmapInfo;
begin
FillChar(bi, sizeof(bi), 0);
bi.bmiHeader.biWidth := FWindowWidth;
bi.bmiHeader.biHeight := -FWindowHeight;
bi.bmiHeader.biPlanes := 1;
bi.bmiHeader.biBitCount := 24;
bi.bmiHeader.biSizeImage := 0;
bi.bmiHeader.biSize := sizeof(TBitmapInfoHeader);
bi.bmiHeader.biClrUsed := 0;
bi.bmiHeader.biClrImportant := 0;
b := TBitmap.Create;
b.Height := 0;
b.Width := FWindowWidth;
b.Height := FWindowHeight;
if SetDIBits(b.Canvas.Handle, b.Handle, 0, FWindowHeight, pData, bi, DIB_RGB_COLORS) = 0 then raise Exception.Create('error');
FWindow.Canvas.StretchDraw(Rect(0, 0, FDisplayWidth, FDisplayHeight), b);
b.Free;
end;
Note that on windows, I pass the parameter
bi.bmiHeader.biHeight := -FWindowHeight;
as negative, so the SetDIBits function displays the image right. If I leave it positive, the image displays mirrored just like I am getting with lazarus.
On lazarus, my code looks like:
procedure display(pData: Pointer);
var
B: HBITMAP;
bmp: TBitmap;
begin
bmp := TBitmap.Create;
B := CreateBitmap(FWindowWidth, FWindowHeight, 1, 24, pData);
if B = 0 then
raise Exception('Error creating bitmap');
bmp.CreateFromBitmapHandles(B, 0, Rect(0, 0, FWindowWidth, FWindowHeight));
FWindow.Canvas.StretchDraw(Rect(0, 0, FDisplayWidth, FDisplayHeight), FOffscreen);
DeleteObject(B);
bmp.Free;
end;
but the image displays mirrored.
Is there an equivallent parameter of the negative parameter of SetDIBits? What is wrong, my image was inverted, or the CreateBitmap inverts it?
Thanks!