如何将数字绘制到图像Delphi 7

Rak*_*tti 3 delphi delphi-7

我需要在图像上绘制一个数字.这个数字会自动改变.我们可以在Delphi 7中动态创建图像吗?如果有人知道,请建议我.

你的拉克什.

RRU*_*RUZ 8

您可以使用a的Canvas属性TBitmap在图像中绘制文本

检查此程序

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;
Run Code Online (Sandbox Code Playgroud)

并使用这样的

procedure TForm1.Button1Click(Sender: TObject);
begin
  GenerateImageFromNumber(10000,'Foo.bmp');
  Image1.Picture.LoadFromFile('Foo.Bmp');//Image1 is a TImage component
end;
Run Code Online (Sandbox Code Playgroud)

  • 我会让GenerateImageFromNumber()返回一个可以分配给TImage的TBitmap,或者让它直接绘制到TImage,而根本不使用临时文件. (4认同)