给你一个: unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type TForm1 = class(TForm) Image1: TImage; Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private procedure GetImage(sStr:string); procedure GetLogFont(iAnc:integer;fCanvas:tCanvas); procedure DrawFive(x,y,r:integer;fCanvas:tCanvas); function GetPoint(nI:integer;nJ:integer;var NAnc:integer):Tpoint; { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); begin if self.Edit1.text='' then exit else GetImage(edit1.Text); end;procedure Tform1.Getimage(sStr:String); var nX,nY,nZ:integer; nPoint:Tpoint; begin nY:=length(widestring(sstr)); if ny>18 then ny:=18; image1.Canvas.Pen.Width:=3; image1.Canvas.Pen.Color:=clred; image1.Canvas.Font.Color:=clred; image1.Canvas.Font.Size:=10;
image1.Canvas.Ellipse(50,20,170,140);//110,80 drawfive(110,80,20,image1.Canvas ); for nx:=1 to ny do begin npoint:=GetPoint(nx,ny,nz); //image1.Canvas.Font.Style:=[fsBold]; getlogfont(nz,image1.Canvas); image1.Canvas.TextOut(npoint.x,npoint.y,copy(widestring(sStr),nx,1)); end; end;procedure Tform1.GetLogFont(iAnc:integer;fCanvas:tCanvas); var FlogFont:LogFont; begin FillChar(FLogFont,Sizeof(TLogFont),0);//先填充一个数据结构 With FlogFont do begin lfHeight:=fCanvas.font.Height; lfWidth:=0; lfEscapement:=iAnc; lforientation:=lfEscapement; lfWeight:=Fw_Normal; lfItalic:=0; lfUnderline:=0; lfStrikeOut:=0; lfCharSet:=GB2312_CHARSET; StrPCopy(lfFaceName,'宋体'); lfQuality:=PROOF_QUALITY; lfOutPrecision:=OUT_TT_ONLY_PRECIS; lfClipPrecision:=CLIP_DEFAULT_PRECIS; lfPitchAndFamily:=Variable_Pitch; end; fCanvas.Font.Handle:=CreateFontIndirect(FLogFont); end; function Tform1.GetPoint(ni:integer;nj:integer;var Nanc:integer):Tpoint; var pPoint:Tpoint; RAn:Extended; tempI:integer; begin {18个字:360 9个字:180 0个字:0 } tempI:=100*(16-nJ+2*nI); if tempI<2700 then tempI:=2700-tempI else tempi:=6300-tempI; Nanc:=tempi-900; ran:=pi*(tempi/1800); pPoint.x:=110+round(55*cos(ran)); pPoint.Y:=80-round(55*sin(ran)); result:=pPoint;end; procedure Tform1.DrawFive(x,y,r:integer;fCanvas:tCanvas); var oldColor:Tcolor; nX:integer; nR:integer; tempRgn:hrgn; pPoint:Array[0..9] of Tpoint; begin for nx:=0 to 9 do begin if (nx mod 2=0) then nR:=r else nR:=round(r*sin(pi/10)/sin(pi*126/180)); pPoint[nx].X:=x+round(nR*cos(pi*(nx/5+0.5))); pPoint[nx].y:=y-round(nR*sin(pi*(nx/5+0.5))); end; oldcolor:=fcanvas.Brush.Color; fcanvas.Brush.Color:=clred; temprgn:=CreatePolygonRgn(ppoint[0],10,ALTERNATE); FillRgn(fcanvas.Handle,temprgn,fcanvas.Brush.Handle);
fcanvas.Brush.Color:=oldcolor; end; procedure TForm1.FormCreate(Sender: TObject); begin edit1.Text:='测试程序有限公司'; end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Image1: TImage;
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure GetImage(sStr:string);
procedure GetLogFont(iAnc:integer;fCanvas:tCanvas);
procedure DrawFive(x,y,r:integer;fCanvas:tCanvas);
function GetPoint(nI:integer;nJ:integer;var NAnc:integer):Tpoint; { Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
if self.Edit1.text='' then
exit
else
GetImage(edit1.Text);
end;procedure Tform1.Getimage(sStr:String);
var
nX,nY,nZ:integer;
nPoint:Tpoint;
begin
nY:=length(widestring(sstr));
if ny>18 then ny:=18; image1.Canvas.Pen.Width:=3;
image1.Canvas.Pen.Color:=clred;
image1.Canvas.Font.Color:=clred;
image1.Canvas.Font.Size:=10;
image1.Canvas.Ellipse(50,20,170,140);//110,80
drawfive(110,80,20,image1.Canvas );
for nx:=1 to ny do begin
npoint:=GetPoint(nx,ny,nz);
//image1.Canvas.Font.Style:=[fsBold];
getlogfont(nz,image1.Canvas);
image1.Canvas.TextOut(npoint.x,npoint.y,copy(widestring(sStr),nx,1)); end;
end;procedure Tform1.GetLogFont(iAnc:integer;fCanvas:tCanvas);
var
FlogFont:LogFont;
begin
FillChar(FLogFont,Sizeof(TLogFont),0);//先填充一个数据结构
With FlogFont do
begin
lfHeight:=fCanvas.font.Height;
lfWidth:=0;
lfEscapement:=iAnc;
lforientation:=lfEscapement;
lfWeight:=Fw_Normal;
lfItalic:=0;
lfUnderline:=0;
lfStrikeOut:=0;
lfCharSet:=GB2312_CHARSET;
StrPCopy(lfFaceName,'宋体');
lfQuality:=PROOF_QUALITY;
lfOutPrecision:=OUT_TT_ONLY_PRECIS;
lfClipPrecision:=CLIP_DEFAULT_PRECIS;
lfPitchAndFamily:=Variable_Pitch;
end;
fCanvas.Font.Handle:=CreateFontIndirect(FLogFont);
end;
function Tform1.GetPoint(ni:integer;nj:integer;var Nanc:integer):Tpoint;
var
pPoint:Tpoint;
RAn:Extended;
tempI:integer;
begin
{18个字:360
9个字:180
0个字:0
}
tempI:=100*(16-nJ+2*nI);
if tempI<2700 then
tempI:=2700-tempI
else
tempi:=6300-tempI; Nanc:=tempi-900; ran:=pi*(tempi/1800);
pPoint.x:=110+round(55*cos(ran));
pPoint.Y:=80-round(55*sin(ran));
result:=pPoint;end;
procedure Tform1.DrawFive(x,y,r:integer;fCanvas:tCanvas);
var
oldColor:Tcolor;
nX:integer;
nR:integer;
tempRgn:hrgn;
pPoint:Array[0..9] of Tpoint;
begin
for nx:=0 to 9 do begin
if (nx mod 2=0) then nR:=r else nR:=round(r*sin(pi/10)/sin(pi*126/180));
pPoint[nx].X:=x+round(nR*cos(pi*(nx/5+0.5)));
pPoint[nx].y:=y-round(nR*sin(pi*(nx/5+0.5)));
end;
oldcolor:=fcanvas.Brush.Color;
fcanvas.Brush.Color:=clred; temprgn:=CreatePolygonRgn(ppoint[0],10,ALTERNATE);
FillRgn(fcanvas.Handle,temprgn,fcanvas.Brush.Handle);
fcanvas.Brush.Color:=oldcolor;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.Text:='测试程序有限公司';
end;end.
image1.Canvas.Ellipse(70,45,150,115);//加入这行
drawfive(110,80,20,image1.Canvas );
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure MyTextOut(Ca:TCanvas;X,Y,Angle:Integer;Text:String);
var
lf : TLogFont;
begin
with Ca do
begin
GetObject(Font.Handle, sizeof(lf), @lf);
lf.lfEscapement := Angle*10;
Font.Handle := CreateFontIndirect(lf);
TextOut(X,Y,Text);
lf.lfEscapement := 0;
lf.lfOrientation := 0;
Font.Handle := CreateFontIndirect(lf);
end;
end;
procedure CircleText(Ca:TCanvas;X0,Y0,RX,RY,BeginAngle,EndAngle:Integer;Text:WideString);
const
aq=180/3.1415926;
qa=3.1415926/180;
procedure _CircleAlpha(Ca:TCanvas;X0,Y0,RX,RY,Angle:Integer;Alpha:WideChar);
var
x,y:Integer;
tw,th:Double;
begin
tw:=Ca.TextWidth(Alpha) / 2;
th:=Ca.TextWidth(Alpha) / 2;
x:=Round(Cos((Angle-90)*qa)*tw)+X0;
y:=Round(Sin((Angle-90)*qa)*tw)+Y0;
x:=Round(Cos(Angle*qa)*RX)+x;
y:=Round(Sin(Angle*qa)*RY)+y;
MyTextOut(Ca,x,y,270-Angle,Alpha);
end;
var
Angle,Step:Double;
n:Integer;
begin
Step:=(EndAngle-BeginAngle)/Length(Text);
Angle:=BeginAngle;
for n:=1 to Length(Text) do
begin
_CircleAlpha(Ca,X0,Y0,RX,RY,Round(Angle),Text[n]);
Angle:=Angle+Step;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Canvas.Font.Name:='宋体';
Canvas.Font.Color:=clBlue;
Canvas.Font.Size:=14;
CircleText(Canvas,200,200,150,150,150,390,'I am Wizardqi(男巫)!');
end;end.
9个字:180
0个字:0
}
//以下求角度 ,预定最多18个字
tempI:=100*(18-nJ+2*(nI-1));
//tempI:=100*(16-nJ+2*nI);
if tempI<2700 then
tempI:=2700-tempI
else
tempi:=6300-tempI;
//这个值就是角度
Nanc:=tempi-900;
th:=Ca.TextWidth(Alpha) / 2; //当间字符中心y,
x:=Round(Cos((Angle-90)*qa)*tw)+X0;
y:=Round(Sin((Angle-90)*qa)*tw)+Y0;
x:=Round(Cos(Angle*qa)*RX)+x;
y:=Round(Sin(Angle*qa)*RY)+y;你能解释一下这个意思吗?
//我的思想是:首先求出每个字在给定中心给定角度的字中心,然后将每个字相对于字中心旋转给定角度即可;
x:=Round(Cos((Angle-90)*qa)*tw)+X0;
y:=Round(Sin((Angle-90)*qa)*tw)+Y0;//求出每个字在给定中心给定角度的字中心
x:=Round(Cos(Angle*qa)*RX)+x;
y:=Round(Sin(Angle*qa)*RY)+y;将每个字相对于字中心旋转给定角度