2011-09-22 5 views

답변

7

이 절차에게 이미지

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; 
+4

내가 GenerateImageFromNumber있을 것 (처럼 사용하기 TBitmapCanvas 속성을 사용할 수 있습니다)는 임시 파일을 전혀 사용하지 않고 TImage에 할당되거나 직접 TImage에 그려지는 TBitmap을 반환합니다. –

+0

감사합니다 ...! – rakesh

+0

@rakesh, 이것이 문제를 해결하면 RRUZ의 대답을 받아 들여야합니다. –

관련 문제