1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
ExtDlgs, BGRABitmapTypes, BGRABitmap; //, BGRATransform;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
OpenPictureDialog1: TOpenPictureDialog;
Panel1: TPanel;
ScrollBar1: TScrollBar;
ScrollBar2: TScrollBar;
ScrollBar3: TScrollBar;
ScrollBar4: TScrollBar;
ScrollBar5: TScrollBar;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Panel1Paint(Sender: TObject);
procedure ScrollBar1Change(Sender: TObject);
private
DisplayBuffer : TBGRABitmap;
SrcBitmap : TBGRABitmap;
public
procedure RotateAndZoom(Ratio:Single; Angle : Single; Opacity : Byte);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
DisplayBuffer := TBGRABitmap.Create(Panel1.ClientWidth, Panel1.ClientHeight);
SrcBitmap := TBGRABitmap.Create;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if openPictureDialog1.Execute then
begin
SrcBitmap.LoadFromFile(OpenPictureDialog1.FileName);
DisplayBuffer.PutImage(0,0,SrcBitmap,dmDrawWithTransparency,255);
Panel1.Invalidate;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeAndNil(DisplayBuffer);
FreeAndNil(SrcBitmap);
end;
procedure TForm1.Panel1Paint(Sender: TObject);
begin
DisplayBuffer.Draw(Panel1.Canvas,0,0);
end;
procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
DisplayBuffer.Canvas.Clear;
RotateAndZoom(Scrollbar1.position / 100, Scrollbar2.Position, ScrollBAr3.Position);
Panel1.Invalidate;
end;
procedure TForm1.RotateAndZoom(Ratio: Single; Angle: Single; Opacity : Byte);
var
LBGRATemp: TBGRABitmap;
LNewWidth, LNewHeight, LMidWidth, LMidHeight : Integer;
begin
LNewWidth := round(SrcBitmap.Width * ratio);
LNewHeight := round(SrcBitmap.Height * ratio);
LMidWidth := LNewWidth shr 1;
LMidHeight := LNewHeight shr 1;
LBGRATemp := SrcBitmap.Resample(LNewWidth, LNewHeight) as TBGRABitmap;
try
DisplayBuffer.PutImageAngle(LMidWidth + ScrollBar4.Position, LMidHeight + ScrollBar5.Position, LBGRATemp,
Angle,
LMidWidth, LMidHeight,Opacity);
finally
LBGRATemp.Free;
end;
end;
end. |
Partager