Sign in Join

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

Mailing lists / lazarus / 2016-07

TImage Question

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Terry A. Haimann

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

Reply by email

leledumbo
to Terry A. Haimann
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;
View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-TImage-Question-tp4048879p4048881.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

Terry A. Haimann
to leledumbo: timage and copy it to the clipboard? Sure, just make a good use of OnMouseDown, OnMouseUp…

Thank You, I'll give that a try.

leledumbo wrote 54 lines
> 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; -- View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-TImage-Question-tp4048879p4048881.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

leledumbo
to Michalis Kamburelis: 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

View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-TImage-Question-tp4048879p4048886.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email