[Lazarus] TImage Question

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] TImage Question

Terry A. Haimann-2
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  

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TImage Question

leledumbo
Administrator
> 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;
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TImage Question

Michalis Kamburelis
2016-07-05 0:51 GMT+02:00 leledumbo <[hidden email]>:
> with bmp do

The "with" statement here is not necessary, as far as I see:)
Michalis
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TImage Question

Terry A. Haimann-2
In reply to this post by leledumbo
Thank You, I'll give that a try.

On Mon, 2016-07-04 at 15:51 -0700, leledumbo wrote:

> > 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 archive at Nabble.com.


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TImage Question

leledumbo
Administrator
In reply to this post by Michalis Kamburelis
> 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