如何在图像上绘制数字Delphi 7 [英] How to draw a Number to an Image Delphi 7
本文介绍了如何在图像上绘制数字Delphi 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在图像上绘制数字。该数字会自动更改。我们如何在Delphi 7中动态创建图像?
。如果有人知道,请建议我。
I have a requirement to draw a number to a image.That number will changes automatically.how can we create an image dynamically in Delphi 7 ? .If any one knows please suggest me.
您的 Rakesh。
推荐答案
您可以使用 TBitmap
可以在图像
You can use the Canvas property of a TBitmap
to draw a text in a image
检查此过程
procedure GenerateImageFromNumber(ANumber:Integer;Const FileName:string);
Var
Bmp : TBitmap;
begin
Bmp:=TBitmap.Create;
try
Bmp.PixelFormat:=pf24bit;
Bmp.Canvas.Font.Name :='Arial';// set the font to use
Bmp.Canvas.Font.Size :=20;//set the size of the font
Bmp.Canvas.Font.Color:=clWhite;//set the color of the text
Bmp.Width :=Bmp.Canvas.TextWidth(IntToStr(ANumber));//calculate the width of the image
Bmp.Height :=Bmp.Canvas.TextHeight(IntToStr(ANumber));//calculate the height of the image
Bmp.Canvas.Brush.Color := clBlue;//set the background
Bmp.Canvas.FillRect(Rect(0,0, Bmp.Width, Bmp.Height));//paint the background
Bmp.Canvas.TextOut(0, 0, IntToStr(ANumber));//draw the number
Bmp.SaveToFile(FileName);//save to a file
finally
Bmp.Free;
end;
end;
并像这样使用
procedure TForm1.Button1Click(Sender: TObject);
begin
GenerateImageFromNumber(10000,'Foo.bmp');
Image1.Picture.LoadFromFile('Foo.Bmp');//Image1 is a TImage component
end;
这篇关于如何在图像上绘制数字Delphi 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文