Sign in Join

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

Mailing lists / lazarus / 2010-05

TImage Canvas not growing with Image? GTK2

6 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

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

theo

Hello

Is it correct, that the paintable area of an Image.Canvas is not growing with the Image?

Example:
Put a TImage on an empty Form. Set Align to alClient.

Then put for ex. this code in Form.OnChangeBounds

procedure TForm1.FormChangeBounds(Sender:TObject);
begin
  With Image1 do
  begin
  Canvas.Brush.Color:=clWhite;
  Canvas.FillRect(0,0,Width,Height);
  Canvas.MoveTo(0,0);
  Canvas.LineTo(Width,Height);
  Canvas.MoveTo(Width,0);
  Canvas.LineTo(0,Height);
  end;
end;

Now resize the form with the Mouse.
For me, the image resizes correctly but the visible area keeps the designtime size.
See: http://www.theo.ch/lazarus/lazimgresize.png
Is it a bug, or is it "by design"?

Lazarus 0.9.29 r25504M FPC 2.4.0 i386-linux-gtk 2 (beta)

Thank you

Reply by email

Marc Weustink
to theo
theo wrote
Hello Is it correct, that the paintable area of an Image.Canvas is not growing with the Image?

No, this is your "problem". The canvas size is exactly the size of the graphic inside the image. It is independent of the size of the TImage.

Example: Put a TImage on an empty Form. Set Align to alClient.

Do you put a graphic in it ? If not I wonder what happens. IIRC an empty TImage has a size of 1x1 pixel, but it maybe it generates a bitmap of the initial TImage size.

Anyway sizing a TImage only changes the dimension of its "viewport" not of the embedded graphic.
If you want such behaviour, use a paintbox

Marc

Reply by email

Mattias Gaertner
to theo: Hello Is it correct, that the paintable area of an Image.Canvas is not growing with the…
Show quoted text 28 lines
Hello Is it correct, that the paintable area of an Image.Canvas is not growing with the Image? Example: Put a TImage on an empty Form. Set Align to alClient. Then put for ex. this code in Form.OnChangeBounds procedure TForm1.FormChangeBounds(Sender:TObject); begin With Image1 do begin Canvas.Brush.Color:=clWhite; Canvas.FillRect(0,0,Width,Height); Canvas.MoveTo(0,0); Canvas.LineTo(Width,Height); Canvas.MoveTo(Width,0); Canvas.LineTo(0,Height); end; end; Now resize the form with the Mouse. For me, the image resizes correctly but the visible area keeps the designtime size. See: http://www.theo.ch/lazarus/lazimgresize.png Is it a bug, or is it "by design"?

By design.
TImage has two canvas, the first is the picture (memory), the second is on the screen.
During OnPaint Canvas is the screen canvas. Otherwise it is an alias for the Picture.Canvas.
You can resize the picture by using Image1.Picture.Width:=100.

Mattias

Reply by email

Hans-Peter Diettrich
to theo
I saw people are using/recommending TImage.Canvas for drawing because drawing is non-volatile, unlike TPaintBox.

An implementation can use either a fixed-size bitmap, so that painting is non-volatile, or recreate the bitmap with every change in size, so that previous content is almost lost.

Fixed-size images, like bitmaps, eventually can be stretch-drawn to the actual extent. Then one can draw into the bitmap, but only within its fixed size.

Truly scalable (vector...) images are not based on a bitmap, and cannot be updated by bitmap-specific graphics commands (LineTo...).

When you re-create your graphics after every change in size, it should be possible to use any "volatile" component (TPanel...) and set its DoubleBuffered property to True.

DoDi

Reply by email