Advertisement
avv210

Move button

Dec 15th, 2021
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.40 KB | None | 0 0
  1. unit UnitTransformation;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TformTransformation }
  13.  
  14.   TformTransformation = class(TForm)
  15.     btnRotate: TButton;
  16.     btnLoad: TButton;
  17.     btnSave: TButton;
  18.     btnMove: TButton;
  19.     btnScale: TButton;
  20.     imgSrc: TImage;
  21.     imgMod: TImage;
  22.     txtNote: TLabel;
  23.     txtImgMod: TLabel;
  24.     txtImgOri: TLabel;
  25.     txtYVal: TLabel;
  26.     txtXVal: TLabel;
  27.     editX: TEdit;
  28.     editY: TEdit;
  29.     openDialog: TOpenDialog;
  30.     saveDialog: TSaveDialog;
  31.     procedure btnLoadClick(Sender: TObject);
  32.     procedure btnMoveClick(Sender: TObject);
  33.     procedure btnSaveClick(Sender: TObject);
  34.     procedure editXChange(Sender: TObject);
  35.     procedure editYChange(Sender: TObject);
  36.   private
  37.  
  38.   public
  39.  
  40.   end;
  41.  
  42. var
  43.   formTransformation: TformTransformation;
  44.  
  45. implementation
  46.  
  47. {$R *.lfm}
  48.  
  49. { TformTransformation }
  50.  
  51. uses Windows;
  52.  
  53. var
  54.   bmpR, bmpG, bmpB : array[0..10000, 0..10000] of byte;
  55.   Tx, Ty : double;
  56.   newX, newY : array[0..10000, 0..10000] of integer;
  57.  
  58. procedure TformTransformation.btnLoadClick(Sender: TObject);
  59. var
  60.   x, y: integer;
  61. begin
  62.   if (openDialog.Execute) then
  63.   begin
  64.     imgSrc.Picture.LoadFromFile(openDialog.FileName);
  65.     for y:=0 to imgSrc.Height-1 do
  66.     begin
  67.       for x:=0 to imgSrc.Width-1 do
  68.       begin
  69.         bmpR[x,y] := getRValue(imgSrc.Canvas.Pixels[x,y]);
  70.         bmpG[x,y] := getGValue(imgSrc.Canvas.Pixels[x,y]);
  71.         bmpB[x,y] := getBValue(imgSrc.Canvas.Pixels[x,y]);
  72.       end;
  73.     end;
  74.   end;
  75. end;
  76.  
  77. procedure TformTransformation.btnMoveClick(Sender: TObject);
  78. var
  79.   x, y: integer;
  80. begin
  81.   for y:=0 to imgSrc.Height-1 do
  82.   begin
  83.     for x:=0 to imgSrc.Width-1 do
  84.     begin
  85.       // TODO: Create a Move button
  86.       newX[Tx + x,y] := Tx + x;
  87.       newY[x,y] := Ty + y;
  88.       imgMod.Canvas.Pixels[newX,newY] := RGB(bmpR[newX,newY], bmpG[newX,newY], bmpB[newX,newY]);
  89.     end;
  90.   end;
  91. end;
  92.  
  93. procedure TformTransformation.btnSaveClick(Sender: TObject);
  94. var
  95.   x, y: integer;
  96. begin
  97.   if (saveDialog.Execute) then
  98.   begin
  99.     imgMod.Picture.SaveToFile(saveDialog.FileName);
  100.   end;
  101. end;
  102.  
  103. procedure TformTransformation.editXChange(Sender: TObject);
  104. begin
  105.   Tx := StrToFloat(editX.text);
  106. end;
  107.  
  108. procedure TformTransformation.editYChange(Sender: TObject);
  109. begin
  110.   Ty := StrToFloat(editY.text);
  111. end;
  112.  
  113. end.
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement