Escrever texto em uma imagem já existente

Delphi

27/12/2007

Pessoal,

Eu estou a procura de uma rotina que carregue uma imagem já existente e se consiga escrever um texto sobre ela. Depois de escrever salvá-la em disco com este texto embutido.

Se não fui claro, por favor, me questionem.

Abraço.
Gonçalves.


Goncalves

Goncalves

Curtidas 0

Respostas

Thiago Vidal

Thiago Vidal

27/12/2007

Utilize a função abaixo, acabei de escrevê-la, nào cheguei a testar, mas deve funcionar.

o código é bem auto-explicativo, mas se tiver alguma duvida pode perguntar

uses
  JPeg;

procedure EscreveTexto(Arquivo: TFileName; X, Y: Integer; Texto: string);
var
  bmp: TBitmap;
  jpg: TJPegImage;
  ext: string;
  IsJpeg: Boolean;
begin
  bmp := TBitmap.Create;
  jpg := TJpegImage.Create;
  try
    ext := LowerCase(ExtractFileExt(Arquivo));
    if (ext = ´.jpg´) or (ext = ´.jpeg´) then
    begin
      jpg.LoadFromFile(Arquivo);
      bmp.Assign(jpg);
      IsJpeg := True;
    end
    else if (ext = ´.bmp´) then
    begin
      bmp.LoadFromFile(Arquivo);
      IsJpeg := False;
    end
    else
      raise Exception.Create(´Tipo de arquivo desconhecido: ´ + ext);

    with bmp.Canvas do
    begin
      Font.Name := ´Arial´;
      Font.Size := 14;
      Font.Style := [fsBold];
      TextOut(X, Y, Texto);
    end;

    if IsJpeg then
    begin
      jpg.Assign(bmp);
      jpg.SaveToFile(Arquivo);
    end
    else
      bmp.SaveToFile(Arquivo);
      
  finally
    jpg.Free;
    bmp.Free;
  end;
end;



GOSTEI 0
Goncalves

Goncalves

27/12/2007

Muito obrigado pela ajuda.
Abraços
Eduardo.


GOSTEI 0
POSTAR