A) Drawing through TBitmap object
The idea is to load a GFL bitmap and convert it into a TBitmap which is then drawn through TCanvas.Draw methods. This solution actually works, but I am rather unhappy with it as it uses a lot of memory and I rather suspect it to be quite slow.
B) Drawing through DIBs
Same as before, I load a GFL bitmap and then convert it (using gflConvertBitmapIntoDib) to a DIB. The DIB is then drawn using this code:
Code: Select all
procedure TXnBitmap.Draw(ACanvas: TCanvas; const Rect: TRect); var Left, Top: integer; PDib: ^BITMAPINFO; begin Left := Rect.Left; Top := Rect.Top; Width := Rect.Right - Rect.Left; Height := Rect.Bottom - Rect.Top; PDib := GlobalLock(Dib); try SetDIBitsToDevice(ACanvas.Handle, Left, Top, Width, Height, 0, 0, 0, Height, @PDib^.bmiColors, PDib^, DIB_RGB_COLORS); finally GlobalUnlock(Dib); end; end;
1. Unless I set ColorModel to GFL_BGRA, the colors are all off (offhand, I would say that red and blue are switched). Curiously, it's not necessary to set GFL_LOAD_FORCE_COLOR_MODEL flag, just setting the ColorModel is enough to correct the problem.
2) The picture is drawn upside down. I suspect it has something to do with the fact that DIBs with Height>0 are bottom-up bitmaps, but I just can't find how to display such a bitmap in a correct direction - either I end up with an upside down picture (using the code above) or with no picture at all.
C) Drawing through DDBs
This would be my prefered method because it should be the fastest. Unfortunatelly, I just can't get any picture out of it. I load a GFL bitmap and convert it to DDB (gflConvertBitmapIntoDdb), but that's about it. The DDB seems to be correct (judging by the memory representation), but I just don't get any picture:
Code: Select all
procedure TXnBitmap.Draw(ACanvas: TCanvas; const Rect: TRect); var Left, Top: integer; BmpDC: HDC; OldObj: HGDIOBJ; begin Left := Rect.Left; Top := Rect.Top; Width := Rect.Right - Rect.Left; Height := Rect.Bottom - Rect.Top; BmpDC := CreateCompatibleDC(ACanvas.Handle); try OldObj := SelectObject(BmpDC, DDB); try BitBlt(ACanvas.Handle, Left, Top, Width, Height, BmpDC, 0, 0, ACanvas.CopyMode); finally SelectObject(BmpDC, OldObj); end; finally DeleteDC(BmpDC); end;
Any help with these problems would be appreciated. I am so close to a working TGraphic based on a LibGFL, but just can't get it to work :-(
Edit: I managed to get the DDB version to work. It turns out I have to use BeginPaint/EndPaint (I would have thought that the Draw method is already in the drawing state, but apparently not). DIB still won't work, though (even with BeginPaint, EndPaint).