Re-learning gdi+[83]: Tgpimage (3)

Source: Internet
Author: User
Tags integer

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.