ImageEn, unit imageenproc

TImageEnProc.TextOut

TImageEnProc.TextOut


Declaration

procedure TextOut(X, Y : Integer; const Text : String; AFont : TFont = nil; Angle : Integer = 0;
                  AntiAlias : Boolean = true; AutoEnlarge : Boolean = False; MeasureOnly: Boolean = False): TRect; overload;
procedure TextOut(X, Y : Integer; const Text : String; const sFontName : String; iFontSize : Integer; cFontColor : TColor; Style : TFontStyles; Angle : Integer = 0;
                  AntiAlias : Boolean = true; AutoEnlarge : Boolean = False; MeasureOnly: Boolean = False): TRect; overload;
procedure TextOut(Rect: TRect; const Text : String; AFont : TFont = nil; Angle : Integer = 0; MeasureOnly: Boolean = False): TRect; overload;
procedure TextOut(Rect: TRect; const Text : String; const sFontName : String; iFontSize : Integer; cFontColor : TColor; Style : TFontStyles; Angle : Integer = 0; MeasureOnly: Boolean = False): TRect; overload;


Description

Draw text at a specified position (no wrapping) or within a rectangle (text may wrap).
Uses DrawText.
For more advanced text drawing, use TextOutEx



Parameter Description
X Horizontal position. Either a pixel value or one of the following constants: Align_Text_Left, Align_Text_Near_Left*, Align_Text_Horz_Center, Align_Text_Near_Right* or Align_Text_Right
Y Vertical position. Either a pixel value or one or one of the following constants: Align_Text_Top, Align_Text_Near_Top*, Align_Text_Vert_Center, Align_Text_Near_Bottom* or Align_Text_Bottom
Rect The bounds for the text output. This will enforce text wrapping and clipping
Text The string to output
AFont The text font can be specified using a TFont or by individual properties. If AFont is passed as nil then the Canvas.Font is used
Angle The Escapement value, i.e. -45 will draws text diagonally downwards (i.e. rotated 45 degrees clockwise)
AntiAlias True uses best quality font. False uses an anti-aliased one
AutoEnlarge If the image is not large enough to fit the text it will be enlarged and filled with Background
MeasureOnly When true the text is not actually drawn, but the result will return the draw rect for the text
* "Near" values provide a 5% buffer from the edge

Result is the draw rect for the text.


Demos

Demo  Demos\ImageEditing\DrawText\DrawText.dpr
Demo  Demos\ImageEditing\EveryMethod\EveryMethod.dpr


Examples

// Add the filename at the bottom centre
ImageEnView1.Proc.TextOut(Align_Text_Horz_Center, Align_Text_Near_Bottom, ExtractFileName(ImageEnView1.IO.Params.Filename), 'Arial', 32, clRed, [fsBold]);


// Do the same but with a soft shadow effect (though you would be better to use a TIETextLayer)

// add a new layer
ImageEnView1.LayersAdd();

// White fill the new layer
ImageEnView1.Proc.Fill(CreateRGB(255, 255, 255));

// Output our text
ImageEnView1.Proc.TextOut(Align_Text_Horz_Center, Align_Text_Near_Bottom, ExtractFileName(ImageEnView1.IO.Params.Filename), 'Arial', 32, clRed, [fsBold]);

// Make the white background transparent
ImageEnView1.Proc.SetTransparentColors(CreateRGB(255, 255, 255), CreateRGB(255, 255, 255), 0); // remove the white, making it as transparent

// Add our shadow
ImageEnView1.Proc.AddSoftShadow(2, 3, 3);

// Merge layer into main window
ImageEnView.LayersMergeAll();


// Draw text onto a TBitmap or TIEBitmap
with TImageEnProc.CreateFromBitmap(myBitmap) do
begin
  TextOut(Align_Text_Horz_Center, Align_Text_Near_Bottom, 'Me in Italy - 2015', 'Arial', 32, clRed, [fsBold]);
  Free();
end;

// Draw text inside a rectangle of (100,100,200,200) auto-wrapping as necessary
ImageEnView1.Proc.TextOut( Rect(100, 100, 200, 200) , 'TImageEnProc provides image processing and analysis functionality to a TImageEnView, TIEBitmap, TImage or TBitmap component. It also handles clipboard operations, undo/redo and encryption.' );