This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs;
Type
TForm1 = Class (Tform)
Procedure Formpaint (Sender:tobject);
Procedure Formcreate (Sender:tobject);
Procedure Formdestroy (Sender:tobject);
Procedure Formmousedown (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Procedure Formmousemove (Sender:tobject; Shift:tshiftstate; X, Y:integer);
Procedure Formmouseup (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Var
Img:tgpimage;
PTS:ARRAY[0..2] of Tgppoint;
Flag:integer =-1;
Procedure Tform1.formcreate (Sender:tobject);
Var
W,h:integer;
Begin
IMG: = tgpimage.create (' C:\temp\test.jpg ');
W: = img. getwidth;
H: = img. GetHeight;
Pts[0]: = Makepoint (clientwidth-w) Div 2 + W, (clientheight-h) Div 2);
PTS[1]: = Makepoint (clientwidth-w) Div 2, (clientheight-h) Div 2);
PTS[2]: = Makepoint (clientwidth-w) Div 2 + W, (clientheight-h) Div 2 + h);
DoubleBuffered: = True;
End
Procedure Tform1.formdestroy (Sender:tobject);
Begin
Img. Free;
End
Procedure Tform1.formmousedown (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Var
I:integer;
Begin
For I: = 0 to Length (pts) do
If PtInRect (Bounds (pts[i). X-3, Pts[i]. Y-3, 6, 6), point (X, Y)) then
Begin
Flag: = i;
Exit;
End
End
Procedure Tform1.formmousemove (Sender:tobject; Shift:tshiftstate; X
Y:integer);
Begin
If flag =-1 then Exit;
Pts[flag]: = Makepoint (X, Y);
Repaint;
End
Procedure Tform1.formmouseup (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Begin
Flag: =-1;
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
P:tgppen;
I:integer;
Begin
G: = Tgpgraphics.create (Self.Canvas.Handle);
P: = tgppen.create (aclred);
{1th: Upper-right corner; 2nd: Upper-left corner; 3rd: lower-right corner; 4th will be based on parallelogram; only three points.}
G.drawimage (IMG, Pgppoint (@pts), Length (pts));
For I: = 0 to Length (pts)-1 Do G.drawrectangle (p, pts[i]. X-3, Pts[i]. Y-3, 6, 6);
P.free;
G.free;
End
End.
Form file:object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 206
ClientWidth = 307
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
OnCreate = FormCreate
OnDestroy = FormDestroy
OnMouseDown = FormMouseDown
OnMouseMove = FormMouseMove
OnMouseUp = FormMouseUp
OnPaint = FormPaint
PixelsPerInch = 96
TextHeight = 13
end