Is is possible to select (with the mouse) a portion of an image on timage and copy it to the clipboard?
Thanks in advance, Terry

Mailing lists / lazarus / 2016-07
5 messages · 3 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Is is possible to select (with the mouse) a portion of an image on timage and copy it to the clipboard?
Thanks in advance, Terry
Is is possible to select (with the mouse) a portion of an image on
timage and copy it to the clipboard?
Sure, just make a good use of OnMouseDown, OnMouseUp and TImage properties and (sub)methods:
uses
ClipBrd;
{$R *.lfm}
var
StartX,StartY,EndX,EndY: Integer;{ TForm1 }
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
StartX := X;
StartY := Y;
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
bmp: TBitmap;
w,h: LongInt;
begin
EndX := X;
EndY := Y;
bmp := TBitmap.Create;
with bmp do
try
w := Abs(EndX - StartX);
h := Abs(EndY - StartY);
bmp.SetSize(w,h);
bmp.Canvas.CopyRect(
Rect(0,0,w,h),
Image1.Canvas,
Rect(StartX,StartY,EndX,EndY)
);
Clipboard.Assign(bmp);
finally
bmp.Free;
end;
end;2016-07-05 0:51 GMT+02:00 leledumbo :
with bmp do
The "with" statement here is not necessary, as far as I see:) Michalis
timage and copy it to the clipboard? Sure, just make a good use of OnMouseDown, OnMouseUp…
Thank You, I'll give that a try.
2016-07-05 0:51 GMT+02:00 leledumbo : The "with" statement here is not necessary, as far…
The "with" statement here is not necessary, as far as I see:)
My bad, I was about to get rid the whole bmp, but realize that I need the variable for Clipboard.Assign and I forget to remove the with :p