请问如何在Canvas上让文字旋转一个已知角度(如90度)(50分)

  • 主题发起人 主题发起人 lwgygz
  • 开始时间 开始时间
L

lwgygz

Unregistered / Unconfirmed
GUEST, unregistred user!
问题如题,在线等待......
 
procedure AngleTextOut(CV: TCanvas; const sText: String; x, y, angle:integer;color:TColor);
var
LogFont: TLogFont;
MyFont,SaveFont: TFont;
begin
SaveFont := TFont.Create;
SaveFont.Assign(CV.Font);
MyFont:= SaveFont;
MyFont.Style := [fsBold];
MyFont.Name := 'Times New Roman';
GetObject(MyFont.Handle, sizeof(TLogFont), @LogFont);
with LogFont do
begin
lfEscapement := angle *10;
lfPitchAndFamily := FIXED_PITCH or FF_DONTCARE;
lfQuality := PROOF_QUALITY;
lfHeight:=30;
//lfStrikeOut := 1;
end; {with}
CV.Font.Handle := CreateFontIndirect(LogFont);
CV.Font.Color := color;
SetBkMode(CV.Handle, TRANSPARENT);
CV.TextOut(x, y, sText);
CV.Font.Assign(SaveFont);
SaveFont.Free;
end;
 
打印时旋转一定角度

procedure TForm1.Button1Click(Sender: TObject);
var
LogRec: TLOGFONT;
OldFont,
NewFont: HFONT;
i, X, Y: LongInt;
begin
if pdPrinter.Execute then begin
with Printer do begin
GetObject(Canvas.Font.Handle,
SizeOf(LogRec), @LogRec);
BeginDoc;
for i := 0 to 5 do begin
LogRec.lfEscapement := (i * 60)*10;
LogRec.lfOutPrecision := OUT_TT_ONLY_PRECIS;
LogRec.lfFaceName := 'Times New Roman';
NewFont := CreateFontIndirect(LogRec);
OldFont := SelectObject(Canvas.Handle,NewFont);
Canvas.TextOut(100, 100, 'Hello World!');
NewFont := SelectObject(
Canvas.Font.Handle,OldFont);
DeleteObject(NewFont);
end; { for }
EndDoc;
end;
end;
end;

 
在FromMouseDown事件中写入:详细请参考http://wolfsoft.nugoo.com 文档中。

var
LogFont:TLogFont;
theFont:TFont;
begin
with Form1.Canvas do
begin
Font.Name:='Arial';
Font.Size:=18;
Font.Color:=clBackground;
theFont:=TFont.Create;
theFont.Assign(Font);
GetObject(theFont.Handle,sizeof(LogFont),@LogFont);
LogFont.lfEscapement:=450;
LogFont.lfOrientation:=450;
theFont.Handle:=CreateFontIndirect(LogFont);
Font.Assign(theFont);
theFont.Free
TextOut(x,y,'黄昏狼制作室');
end;
end;
 
给个会动的转角度的例子给你:慢慢参考
unit SideTxtF;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
Timer1: TTimer;
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormPaint(Sender: TObject);
var
ALogFont: TLogFont;
hFont: THandle;
begin
ALogFont.lfHeight := Font.Height;
ALogFont.lfWidth := 0;
ALogFont.lfEscapement := 900;
ALogFont.lfOrientation := 900;
ALogFont.lfWeight := fw_DemiBold;
ALogFont.lfItalic := 0; // false
ALogFont.lfUnderline := 0; // false
ALogFont.lfStrikeOut := 0; // false
ALogFont.lfCharSet := Ansi_CharSet;
ALogFont.lfOutPrecision := Out_Default_Precis;
ALogFont.lfClipPrecision := Clip_Default_Precis;
ALogFont.lfQuality := Default_Quality;
ALogFont.lfPitchAndFamily := Default_Pitch;
StrCopy (ALogFont.lfFaceName, PChar (Font.Name));
hFont := CreateFontIndirect (ALogFont);
Canvas.Font.Handle := hFont;
Canvas.TextOut (0, ClientHeight, 'Hello');
end;

procedure TForm1.FormCreate(Sender: TObject);
var
ALogFont: TLogFont;
hFont: THandle;
begin
ALogFont.lfHeight := Font.Height;
ALogFont.lfWidth := 0;
ALogFont.lfEscapement := -450;
ALogFont.lfOrientation := -450;
ALogFont.lfWeight := fw_DemiBold;
ALogFont.lfItalic := 0; // false
ALogFont.lfUnderline := 0; // false
ALogFont.lfStrikeOut := 0; // false
ALogFont.lfCharSet := Ansi_CharSet;
ALogFont.lfOutPrecision := Out_Default_Precis;
ALogFont.lfClipPrecision := Clip_Default_Precis;
ALogFont.lfQuality := Default_Quality;
ALogFont.lfPitchAndFamily := Default_Pitch;
StrCopy (ALogFont.lfFaceName, PChar (Font.Name));
hFont := CreateFontIndirect (ALogFont);
Font.Handle := hFont;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
ALogFont: TLogFont;
hFont: THandle;
begin
ALogFont.lfHeight := Font.Height;
ALogFont.lfWidth := 0;
ALogFont.lfEscapement := - (GetTickCount div 10) mod 3600;
ALogFont.lfOrientation := ALogFont.lfEscapement;
ALogFont.lfWeight := fw_DemiBold;
ALogFont.lfItalic := 0; // false
ALogFont.lfUnderline := 0; // false
ALogFont.lfStrikeOut := 0; // false
ALogFont.lfCharSet := Ansi_CharSet;
ALogFont.lfOutPrecision := Out_Default_Precis;
ALogFont.lfClipPrecision := Clip_Default_Precis;
ALogFont.lfQuality := Default_Quality;
ALogFont.lfPitchAndFamily := Default_Pitch;
StrCopy (ALogFont.lfFaceName, PChar (Font.Name));
hFont := CreateFontIndirect (ALogFont);
Canvas.Font.Handle := hFont;
Canvas.TextOut (300, 200, '春意');
end;

end.
 
首先谢谢楼上几位大虾的帮助,但我还想问一个问题,就是如何已知一条线段,在该线段
的终点画一条与之垂直的线段(设已知该线段的长度)。
 
多人接受答案了。
 

Similar threads

后退
顶部