Delphi implementation Image text rotation effect complete instance code _delphi

Source: Internet
Author: User
Tags textout

This paper illustrates the solution of Delphi to realize the effect of image text rotation by example, and the control used in this program is mainly panel control, image control, Edit control, Label Control and button control. The key of this program is to use the bmp_rotate () function of Delphi to realize the function of rotating image. and skillfully invoke the relevant Windows API functions to achieve the rotation effects on the text.

The complete instance code is as follows:

Unit Unit1;
Interface uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs,math, Stdctrls, Extctrls;
Type TFORM1 = Class (Tform) Edit1:tedit;
Image1:timage;
Bmprotate:tbutton;
Label1:tlabel;
Panel1:tpanel;
Image2:timage;
Panel2:tpanel;
Image3:timage;
Edit2:tedit;
Rotatedtext:tbutton;
Label2:tlabel;
Procedure Bmprotateclick (Sender:tobject);
Procedure Rotatedtextclick (Sender:tobject);
Procedure Formcreate (Sender:tobject);
Private {Private declarations} public {public declarations} procedure bmp_rotate (src,dst:tbitmap;angle:extended); Procedure Drawrotatedtext (Thecanvas:tcanvas;
Theangle:integer;
thetext:string);
End
var Form1:tform1; Implementation {$R *.
DFM} procedure Tform1.bmp_rotate (src,dst:tbitmap;angle:extended);//image rotation Var C1x,c1y,c2x,c2y:integer;
P1x,p1y,p2x,p2y:integer;
Radius,n:integer;
alpha:extended;
C0,c1,c2,c3:tcolor; Begin angle: = (angle/180) * PI; Converts the content in a text box to the angle c1x: = src.
Width Div 2; C1Y: = src.
Height Div 2; C2X: = dsT.width Div 2; C2Y: = DST.
Height Div 2;
If c2x < c2y then n: = c2y else N: = c2x; Dec (n,1); Reduce the N value 1,n:=n-1 for p2x: = 0 to n does begin for P2Y: = 0 to n do begin if P2X = 0 Then alpha:= pi/2 else alpha: = Arctan2 (
P2Y,P2X); Radius: = Round (sqrt (P2X*P2X) + (P2Y*P2Y))//Set radius of rotation when rotated p1x: = round (RADIUS * cos (angle+alpha)); Set the center axis of rotation p1y: = round (RADIUS * sin (angle+alpha)); Set Rotation Center ordinate c0: = src. canvas.pixels[c1x+p1x,c1y+p1y];//replaces pixel C1 at the associated coordinates of the image: = src.
CANVAS.PIXELS[C1X-P1X,C1Y-P1Y]; C2: = src.
CANVAS.PIXELS[C1X+P1Y,C1Y-P1X]; C3: = src.
CANVAS.PIXELS[C1X-P1Y,C1Y+P1X]; Dst. CANVAS.PIXELS[C2X+P2X,C2Y+P2Y]:=C0; Swap pixel points in different locations for DST.
CANVAS.PIXELS[C2X-P2X,C2Y-P2Y]:=C1; Dst.
CANVAS.PIXELS[C2X+P2Y,C2Y-P2X]:=C2; Dst.
CANVAS.PIXELS[C2X-P2Y,C2Y+P2X]:=C3;
End
Application.processmessages//Response to other message request end;
End
Procedure Tform1.bmprotateclick (Sender:tobject);
Var rangle:extended; Begin Rangle: = Strtofloat (Edit1.text); Set the angle of rotation bmp_rotate (Image1.picture.bitmap,image2.picture.bitmap, rangle);//Run the rotation function,Rotate the graphics end; Procedure Tform1.drawrotatedtext (Thecanvas:tcanvas;
Theangle:integer;
thetext:string);
var Lf:tlogfont;
Tf:tfont;
Begin Image3.Canvas.refresh;
With Thecanvas do begin font.name:= ' Arial ';
font.size:=18;
Brush.style:= bsclear;
Tf:= tfont.create; Try TF.
Assign (Font); GetObject (TF. Handle, Sizeof (LF), @lf);
Assigns the current instance handle to the TF this font object lf.lfescapement:=theangle*10; Lf.lforientation: = Theangle * 10; Causes the horizontal axis and horizontal line to be entered at the specified angle TF. Handle: = CreateFontIndirect (LF); Create a Font specific object font.assign (TF); Make this object apply to the program finally TF. Free;
Release object end; TextOut (Image3.left, image3.top+20, thetext);
Draws the text to the specified area end;
End
Procedure Tform1.rotatedtextclick (Sender:tobject);
Var Theangle:integer; Begin Theangle: = Strtoint (Edit2.text); Converts the text in the text box to the angle Drawrotatedtext (Image3.canvas, Theangle, ' Delphi Graphics Studio ');
Call the rotated text function end;
Procedure Tform1.formcreate (Sender:tobject);
var Tf:tfont;
thetext:string; Begin Thetext:= ' Delphi Graphics Studio '; Sets the text with the Image3.canvas do begin font.name: = ' Arial '; Set Font Font.sIze: = 18; Set Font size Brush.style: = Bsclear; Set brush style tf:= tfont.create; Create a font specific object TextOut (Image3.left, image3.top+20, thetext);
Draws the text to the specified area end;
End 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.