this slowpoke moves

Move JGP flicker-free

uses Jpeg

private
	{ Private declarations }
    DownPoint, MovePoint, UpPoint : TPoint;
    Jpg : TJPEGImage;
    
//

procedure TForm1.FormCreate(Sender: TObject);
var
  Pfad: AnsiString;
begin
  Panel1.DoubleBuffered:= true;
  Pfad:= ExtractFilePath(application.ExeName)+ 'bild.jpg';
  if FileExists(Pfad) then
  begin
    Jpg := TJPEGImage.Create;
    Jpg.LoadFromFile(Pfad);
    Image1.Canvas.Draw(10, 10, Jpg);
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  if Assigned(Jpg) then
    Jpg.Free;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if ssLeft in Shift then
  begin
    DownPoint.X:= x;
    DownPoint.Y:= y;
  end;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if ssLeft in Shift then
  begin
    MovePoint.X := UpPoint.X + X- DownPoint.X;
    MovePoint.Y := UpPoint.Y + Y - DownPoint.Y;
    
    if MovePoint.X > 0 then
      MovePoint.X := 0;

    if MovePoint.y > 0 then
      MovePoint.Y := 0;

    if MovePoint.X < (Jpg.Width- Image1.Width)* - 1 then
      MovePoint.X := (Jpg.Width- Image1.Width)* - 1;

    if MovePoint.Y < (Jpg.Height- Image1.Height)* -1 then
      MovePoint.Y := (Jpg.Height- Image1.Height)* -1;

    Image1.Canvas.Draw(MovePoint.X, MovePoint.Y, Jpg);
    Image1.Refresh;
  end;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   UpPoint.X:= MovePoint.X;
   UpPoint.Y:= MovePoint.Y;
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate