Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2025-02

FPImage to LCL. How to do it?

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Giuliano Colla

I have an application where I need to rotate an image for displaying in an LCL image. The image is a clock face, the image to rotate is each of the hands.
I can get the bitmap from the source LCL image, and copy the rectangle from the LCL image canvas to the FPImage canvas.
I can rotate it, but I'm unable to copy back the resulting image to the LCL canvas, because I'm told that the  TFPImageCanvas is an "incompatible type" with TCanvas.
The only way I've found to get back the rotated image is to save it as a PNG to a file, and then load the PNG file, which of course is not a good way to do it.
Am I missing a point or something is missing in the FPImage implementation?

Any hints?

Giuliano

Do not do to others as you would have them do to you.They might have different tastes.

Reply by email

Mattias Gaertner
to Giuliano Colla
Giuliano Colla wrote 8 lines
I have an application where I need to rotate an image for displaying in an LCL image. The image is a clock face, the image to rotate is each of the hands. I can get the bitmap from the source LCL image, and copy the rectangle from the LCL image canvas to the FPImage canvas. I can rotate it, but I'm unable to copy back the resulting image to the LCL canvas, because I'm told that the  TFPImageCanvas is an "incompatible type" with TCanvas.

If you have a FPImage canvas, then you should have a TFPCustomImage. Preferably a LazIntfImage, preferably initialized to the same format as the LCL widgetset.

uses ..., IntfGraphics, LCLType, LCLIntf;
var
   LazImg: TLazIntfImage;
   BitmapHnd, DummyHnd: HBITMAP;
   LCLCanvas: TCanvas;
   RotatedWidth, RotatedHeight, x, y: Integer;
begin
   LCLCanvas:=Canvas;
   RotatedWidth:=100;
   RotatedHeight:=100;
   x:=0;
   y:=0;
   // create a memory image
   LazImg := TLazIntfImage.Create(0,0,[]);
   LazImg.DataDescription := GetDescriptionFromDevice(LCLCanvas.Handle,
      RotatedWidth,RotatedHeight);
   // draw the rotated image to the LazImg ...
   // create the widgetset bitmap
   LazImg.CreateBitmaps(BitmapHnd, DummyHnd, True);
   StretchBlt(LCLCanvas.Handle,x,y,LazImg.Width,LazImg.Height,
       BitmapHnd, 0,0,LazImg.Width,LazImg.Height, LCLCanvas.CopyMode);
end;

Mattias

Reply by email

Giuliano Colla
to Mattias Gaertner

Thanks a lot, Mattias. I had to struggle a bit with widgetsets because each one had some problems. I'm on Linux, and at the end the Qt WS (i.e. Qt4) is the only one with gives an acceptable result, with the only problem of a little memory leakage I've not been able to get rid of. But finally I have a Clock face with a rotated hand:

Minutes and seconds hands will follow....

Giuliano

Il 24/02/25 21:47, Mattias Gaertner via fpc-devel ha scritto:

If you have a FPImage canvas, then you should have a TFPCustomImage. Preferably a LazIntfImage, preferably initialized to the same format as the LCL widgetset.
Do not do to others as you would have them do to you.They might have different tastes.

Reply by email