如何将字符串生成bmp文件,并且字符串在bmp文件是任意角度,0,90,180,270。(50分)

  • 主题发起人 主题发起人 yuanjj76
  • 开始时间 开始时间
Y

yuanjj76

Unregistered / Unconfirmed
GUEST, unregistred user!
如何将字符串生成bmp文件,并且字符串在bmp文件是任意角度,0,90,180,270。
 
在form上放个memo,装入txt,再用form.canvas.savetofile
这样就可以把文本转成图形了,再把图形旋转就可以了

 
在程序里如何实现自动旋转呢,谢谢
 
form.canvas我找不到savetofile???你能详细点吧
 
Create 一个 TBitmap, 在 TBitmap 的 Canvas 上 TextOut 你的字符串,然后旋转就可

或者用 TLogFont 将字符串旋转后再 TextOut 到 TBitmap 的 Canvas 上。
 
procedure DrawSingleWordData(cCanvas:TCanvas;IDX,LayerIDX:Integer;DrawSelected:Boolean);
var
OldFont,TempFont : TFont;
pTemp : TPoint;
sTemp : WideString;
plf : LOGFONT;
iFontHeight,i:Integer;
bDraw:Boolean;
OldBrushStyle:TBrushStyle;
WordPoints:TAPoint4;
begin
OldFont:=TFont.Create;
TempFont:=TFont.Create;
try
with cCanvas do
begin
OldFont.Assign(Font);
OldBrushStyle:=Brush.Style;
try
bDraw:=RWordData(FWordData[IDX]^).iFontSize*FMapCenter.fScale>5;
if bDraw then
begin
sTemp:= Trim(RWordData(FWordData[IDX]^).sName);
iFontHeight:=RWordData(FWordData[IDX]^).iHeight;
if FScaleWord then
iFontHeight:=Round(RWordData(FWordData[IDX]^).iHeight*FMapCenter.fScale);
pTemp:= Point(RWordData(FWordData[IDX]^).iX, RWordData(FWordData[IDX]^).iY);
pTemp:= funChangeMapToScreen(pTemp);

with plf do
begin
lfHeight:= iFontHeight;
lfWidth:= 0;
lfEscapement:= RWordData(FWordData[IDX]^).iFontAngle*10;
lfOrientation:= 0;
lfWeight:= FW_NORMAL;

lfItalic:= 0;
lfUnderline:= 0;
lfStrikeOut:= 0;

lfCharSet:= DEFAULT_CHARSET;
StrPCopy(lfFaceName, RWordData(FWordData[IDX]^).sFontName);
lfQuality:= DEFAULT_QUALITY;
lfOutPrecision:= OUT_DEFAULT_PRECIS;
lfClipPrecision:= CLIP_DEFAULT_PRECIS;
lfPitchAndFamily:= DEFAULT_PITCH;
end;

TempFont.Assign(Font);
TempFont.Handle:= CreateFontIndirect(plf);
try
Font.Assign(TempFont);
Font.Color:=RWordData(FWordData[IDX]^).cFontColor;
Brush.Style:=bsClear;
TextOut(pTemp.x,pTemp.y,sTemp);
finally
SetLastError(0);
DeleteObject(TempFont.Handle);
if GetLastError<>0 then
raise Exception.Create(SysErrorMessage(GetLastError));
end;
if DrawSelected then
begin
Pen.Color:=clBlue;
Brush.Color:=clBlue;

WordPoints:=FunGetWordRegion(RWordData(FWordData[IDX]^));
Polyline(WordPoints);
MoveTo(WordPoints[3].x,WordPoints[3].y);
LineTo(WordPoints[0].x,WordPoints[0].y);

Brush.Color:=clRed;
Pen.Color:=clRed;
Pen.Width:=1;
For i:=0 to High(WordPoints) do
Rectangle(WordPoints.x-PointWidth,WordPoints.y-PointWidth,WordPoints.x+PointWidth,WordPoints.Y+PointWidth);
end;
end;
finally
Brush.Style:=OldBrushStyle;
Font.Assign(OldFont);
end;
end;
finally
OldFont.Free;
TempFont.Free;
end;
end;

var bitmap:tbitmap;
begin
bitmap:=tbitmap.create;
bitmap.width:=600;
bitmap.height:=400;
DrawSingleWordData(bitmap.Canvas,0,0,false);
bitmap.savetofile('yourbitmap.bmp');
bitmap.free;
end;
 
多人接受答案了。
 

Similar threads

回复
0
查看
1K
不得闲
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
900
SUNSTONE的Delphi笔记
S
后退
顶部