I rewrited it to use DrawFocusRect but still not solve my problem with copying selected part...
from left to right working, from right to left = fail.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Image: TImage;
Image2: TImage;
procedure FormCreate(Sender: TObject);
procedure ImageMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
);
procedure ImageMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
Drawing : boolean ;
P : TPoint ;
P2 : TPoint ;
implementation
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Drawing := False ;
end;
procedure TForm1.ImageMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Drawing := True ;
P := Point(X, Y) ;
P2 := P ;
Image.Canvas.DrawFocusRect(Rect(x, y, x, y));
Image.Picture.LoadFromFile('/home/laboratory2/Desktop/test.bmp');
end;
procedure TForm1.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Drawing = true then
begin
Image.Canvas.DrawFocusRect(Rect(P.x, P.y, P2.x,P2.y));
P2 := Point(x, y);
Image.Canvas.DrawFocusRect(Rect(P.x, P.y, x, y));
end;
end;
procedure TForm1.ImageMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
B: TBitmap ;
Bitmapa:TBitmap;
begin
Image.Canvas.DrawFocusRect(Rect(P.x, P.y, P2.x, P2.y));
Image.Canvas.DrawFocusRect(Rect(P.x, P.y, x, y));
//P := Point(x, y);
Drawing := False ;
B := TBitmap.Create ;
B.Width := Round(abs(P2.x - P.x));
B.Height := Round(abs(P2.y - P.y));
B.Canvas.CopyRect(Rect(0, 0, b.Width, b.Height), Image.Canvas,
Rect(P.X, P.Y, P2.X, P2.Y));
Image2.Width := Round(abs(P2.x - P.x));
Image2.Height := Round(abs(P2.y - P.y));
// showmessage(inttostr(B.Width));
// showmessage(inttostr(B.height));
Image2.Canvas.Draw(0, 0, B);
//B.SaveToFile('C:\somthing.bmp');
end;
initialization
{$I unit1.lrs}
end.