[Lazarus] TImage Question

leledumbo leledumbo_cool at yahoo.co.id
Tue Jul 5 00:51:56 CEST 2016


> 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.


More information about the Lazarus mailing list