Ir para conteúdo
Fórum Script Brasil
  • 0

Gerando Imagem apartir de um texto?


Pedro SI

Pergunta

Boa Tarde a Todos,

Hoje tenho um sistema que é desenvolvido em Delphi 7 e utiliza a base do Crystal Para a geração de relatórios,

Com a entrada a NFe no Brasil tivemos que criar o próprio algoritimo para que o cristal imprima o código e que a leitora o reconheça,

a lógica para que isto ocorra está correta, meu unico problema é:

quando exporto o boleto para PDF e envio para alguém que não possua a fonta exatamente igual a minha instalada ele não demonstra o codigo de barras!

será que alguém possue alguma formula em delphi que ao invé de gerar uma String, gere diretamente uma imagem.bmp ou .jpg, bom de qualquer formato se possivel uma linha de comando interna do crystal,

Por Favor até o momento não consegui encontrar nada,

Grato Pela atenção,

Um grande Abraço,

Pedro Henrique.

Link para o comentário
Compartilhar em outros sites

6 respostass a esta questão

Posts Recomendados

  • 0
quando exporto o boleto para PDF e envio para alguém que não possua a fonte exatamente igual a minha instalada ele não demonstra o codigo de barras!

envie a fonte junto com o pdf ou então procure por uma fonte que seja comum a todos.

abraço

Link para o comentário
Compartilhar em outros sites

  • 0

Muito obrigado pessoal!

a fonte code 128 que utilizo é esta: http://ultradownloads.uol.com.br/download-fonte/Code-128/

está upada no ultra downloads do uol.

e o o algoritimo que eu fiz para que o crystal gere os caracteres de cod de barras é este:

Shared StringVar VGEntrada;

Shared StringVar VGSaida;

Shared NumberVar VGNumeroBarra;

StringVar VLCodigoBarras := '';

StringVar VLCheckNumber := '';

NumberVar VLRestoDivisao;

NumberVar VLDigitoVerificador := 0;

NumberVar VLIndice;

NumberVar VLDigitoSequencia :=1;

for VLIndice := 1 to 44 step 2 do

(

VGEntrada := mid({VDNOTAELETRONICA.CHAVEACESSO},VLIndice,2);

//--------------------------------------//

//------Verifica Criptografia-----------//

//--------------------------------------//

if(VGEntrada = '00')then VGSaida := ' ';

if(VGEntrada = '01')then VGSaida := '!';

if(VGEntrada = '02')then VGSaida := '"';

if(VGEntrada = '03')then VGSaida := '#';

if(VGEntrada = '04')then VGSaida := '$';

if(VGEntrada = '05')then VGSaida := '%';

if(VGEntrada = '06')then VGSaida := '&';

if(VGEntrada = '07')then VGSaida := '''';

if(VGEntrada = '08')then VGSaida := '(';

if(VGEntrada = '09')then VGSaida := ')';

if(VGEntrada = '10')then VGSaida := '*';

if(VGEntrada = '11')then VGSaida := '+';

if(VGEntrada = '12')then VGSaida := ',';

if(VGEntrada = '13')then VGSaida := '-';

if(VGEntrada = '14')then VGSaida := '.';

if(VGEntrada = '15')then VGSaida := '/';

if(VGEntrada = '16')then VGSaida := '0';

if(VGEntrada = '17')then VGSaida := '1';

if(VGEntrada = '18')then VGSaida := '2';

if(VGEntrada = '19')then VGSaida := '3';

if(VGEntrada = '20')then VGSaida := '4';

if(VGEntrada = '21')then VGSaida := '5';

if(VGEntrada = '22')then VGSaida := '6';

if(VGEntrada = '23')then VGSaida := '7';

if(VGEntrada = '24')then VGSaida := '8';

if(VGEntrada = '25')then VGSaida := '9';

if(VGEntrada = '26')then VGSaida := ':';

if(VGEntrada = '27')then VGSaida := ';';

if(VGEntrada = '28')then VGSaida := '<';

if(VGEntrada = '29')then VGSaida := '=';

if(VGEntrada = '30')then VGSaida := '>';

if(VGEntrada = '31')then VGSaida := '?';

if(VGEntrada = '32')then VGSaida := '@';

if(VGEntrada = '33')then VGSaida := 'A';

if(VGEntrada = '34')then VGSaida := 'B';

if(VGEntrada = '35')then VGSaida := 'C';

if(VGEntrada = '36')then VGSaida := 'D';

if(VGEntrada = '37')then VGSaida := 'E';

if(VGEntrada = '38')then VGSaida := 'F';

if(VGEntrada = '39')then VGSaida := 'G';

if(VGEntrada = '40')then VGSaida := 'H';

if(VGEntrada = '41')then VGSaida := 'I';

if(VGEntrada = '42')then VGSaida := 'J';

if(VGEntrada = '43')then VGSaida := 'K';

if(VGEntrada = '44')then VGSaida := 'L';

if(VGEntrada = '45')then VGSaida := 'M';

if(VGEntrada = '46')then VGSaida := 'N';

if(VGEntrada = '47')then VGSaida := 'O';

if(VGEntrada = '48')then VGSaida := 'P';

if(VGEntrada = '49')then VGSaida := 'Q';

if(VGEntrada = '50')then VGSaida := 'R';

if(VGEntrada = '51')then VGSaida := 'S';

if(VGEntrada = '52')then VGSaida := 'T';

if(VGEntrada = '53')then VGSaida := 'U';

if(VGEntrada = '54')then VGSaida := 'V';

if(VGEntrada = '55')then VGSaida := 'W';

if(VGEntrada = '56')then VGSaida := 'X';

if(VGEntrada = '57')then VGSaida := 'Y';

if(VGEntrada = '58')then VGSaida := 'Z';

if(VGEntrada = '59')then VGSaida := '[';

if(VGEntrada = '60')then VGSaida := '\';

if(VGEntrada = '61')then VGSaida := ']';

if(VGEntrada = '62')then VGSaida := '^';

if(VGEntrada = '63')then VGSaida := '_';

if(VGEntrada = '64')then VGSaida := '`';

if(VGEntrada = '65')then VGSaida := 'a';

if(VGEntrada = '66')then VGSaida := 'b';

if(VGEntrada = '67')then VGSaida := 'c';

if(VGEntrada = '68')then VGSaida := 'd';

if(VGEntrada = '69')then VGSaida := 'e';

if(VGEntrada = '70')then VGSaida := 'f';

if(VGEntrada = '71')then VGSaida := 'g';

if(VGEntrada = '72')then VGSaida := 'h';

if(VGEntrada = '73')then VGSaida := 'i';

if(VGEntrada = '74')then VGSaida := 'j';

if(VGEntrada = '75')then VGSaida := 'k';

if(VGEntrada = '76')then VGSaida := 'l';

if(VGEntrada = '77')then VGSaida := 'm';

if(VGEntrada = '78')then VGSaida := 'n';

if(VGEntrada = '79')then VGSaida := 'o';

if(VGEntrada = '80')then VGSaida := 'p';

if(VGEntrada = '81')then VGSaida := 'q';

if(VGEntrada = '82')then VGSaida := 'r';

if(VGEntrada = '83')then VGSaida := 's';

if(VGEntrada = '84')then VGSaida := 't';

if(VGEntrada = '85')then VGSaida := 'u';

if(VGEntrada = '86')then VGSaida := 'v';

if(VGEntrada = '87')then VGSaida := 'w';

if(VGEntrada = '88')then VGSaida := 'x';

if(VGEntrada = '89')then VGSaida := 'y';

if(VGEntrada = '90')then VGSaida := 'z';

if(VGEntrada = '91')then VGSaida := '{';

if(VGEntrada = '92')then VGSaida := '|';

if(VGEntrada = '93')then VGSaida := '}';

if(VGEntrada = '94')then VGSaida := '~';

if(VGEntrada = '95')then VGSaida := 'Â';

if(VGEntrada = '96')then VGSaida := 'Ä';

if(VGEntrada = '97')then VGSaida := 'Å';

if(VGEntrada = '98')then VGSaida := 'Æ';

if(VGEntrada = '99')then VGSaida := 'Ç';

//--------------------------------------//

//--------------------------------------//

//--------------------------------------//

VLCodigoBarras := VLCodigoBarras + VGSaida;

VGNumeroBarra := toNumber(VGEntrada);

VLDigitoVerificador := VLDigitoVerificador + (VGNumeroBarra * VLDigitoSequencia);

VLDigitoSequencia := VLDigitoSequencia + 1;

);

VLDigitoVerificador := VLDigitoVerificador + 105;

VLRestoDivisao := Remainder (VLDigitoVerificador, 103);

VLCheckNumber := toText(VLRestoDivisao,'00');

VGEntrada := VLCheckNumber;

//--------------------------------------//

//------Verifica Criptografia-----------//

//--------------------------------------//

if(VGEntrada = '00')then VGSaida := ' ';

if(VGEntrada = '01')then VGSaida := '!';

if(VGEntrada = '02')then VGSaida := '"';

if(VGEntrada = '03')then VGSaida := '#';

if(VGEntrada = '04')then VGSaida := '$';

if(VGEntrada = '05')then VGSaida := '%';

if(VGEntrada = '06')then VGSaida := '&';

if(VGEntrada = '07')then VGSaida := '''';

if(VGEntrada = '08')then VGSaida := '(';

if(VGEntrada = '09')then VGSaida := ')';

if(VGEntrada = '10')then VGSaida := '*';

if(VGEntrada = '11')then VGSaida := '+';

if(VGEntrada = '12')then VGSaida := ',';

if(VGEntrada = '13')then VGSaida := '-';

if(VGEntrada = '14')then VGSaida := '.';

if(VGEntrada = '15')then VGSaida := '/';

if(VGEntrada = '16')then VGSaida := '0';

if(VGEntrada = '17')then VGSaida := '1';

if(VGEntrada = '18')then VGSaida := '2';

if(VGEntrada = '19')then VGSaida := '3';

if(VGEntrada = '20')then VGSaida := '4';

if(VGEntrada = '21')then VGSaida := '5';

if(VGEntrada = '22')then VGSaida := '6';

if(VGEntrada = '23')then VGSaida := '7';

if(VGEntrada = '24')then VGSaida := '8';

if(VGEntrada = '25')then VGSaida := '9';

if(VGEntrada = '26')then VGSaida := ':';

if(VGEntrada = '27')then VGSaida := ';';

if(VGEntrada = '28')then VGSaida := '<';

if(VGEntrada = '29')then VGSaida := '=;

if(VGEntrada = '30')then VGSaida := '>';

if(VGEntrada = '31')then VGSaida := '?';

if(VGEntrada = '32')then VGSaida := '@';

if(VGEntrada = '33')then VGSaida := 'A';

if(VGEntrada = '34')then VGSaida := 'B';

if(VGEntrada = '35')then VGSaida := 'C';

if(VGEntrada = '36')then VGSaida := 'D';

if(VGEntrada = '37')then VGSaida := 'E';

if(VGEntrada = '38')then VGSaida := 'F';

if(VGEntrada = '39')then VGSaida := 'G';

if(VGEntrada = '40')then VGSaida := 'H';

if(VGEntrada = '41')then VGSaida := 'I';

if(VGEntrada = '42')then VGSaida := 'J';

if(VGEntrada = '43')then VGSaida := 'K';

if(VGEntrada = '44')then VGSaida := 'L';

if(VGEntrada = '45')then VGSaida := 'M';

if(VGEntrada = '46')then VGSaida := 'N';

if(VGEntrada = '47')then VGSaida := 'O';

if(VGEntrada = '48')then VGSaida := 'P';

if(VGEntrada = '49')then VGSaida := 'Q';

if(VGEntrada = '50')then VGSaida := 'R';

if(VGEntrada = '51')then VGSaida := 'S';

if(VGEntrada = '52')then VGSaida := 'T';

if(VGEntrada = '53')then VGSaida := 'U';

if(VGEntrada = '54')then VGSaida := 'V';

if(VGEntrada = '55')then VGSaida := 'W';

if(VGEntrada = '56')then VGSaida := 'X';

if(VGEntrada = '57')then VGSaida := 'Y';

if(VGEntrada = '58')then VGSaida := 'Z';

if(VGEntrada = '59')then VGSaida := '[';

if(VGEntrada = '60')then VGSaida := '\';

if(VGEntrada = '61')then VGSaida := ]';

if(VGEntrada = '62')then VGSaida := '^';

if(VGEntrada = '63')then VGSaida := '_';

if(VGEntrada = '64')then VGSaida := '`';

if(VGEntrada = '65')then VGSaida := 'a';

if(VGEntrada = '66')then VGSaida := 'b';

if(VGEntrada = '67')then VGSaida := 'c';

if(VGEntrada = '68')then VGSaida := 'd';

if(VGEntrada = '69')then VGSaida := 'e';

if(VGEntrada = '70')then VGSaida := 'f';

if(VGEntrada = '71')then VGSaida := 'g';

if(VGEntrada = '72')then VGSaida := 'h';

if(VGEntrada = '73')then VGSaida := 'i';

if(VGEntrada = '74')then VGSaida := 'j';

if(VGEntrada = '75')then VGSaida := 'k';

if(VGEntrada = '76')then VGSaida := 'l';

if(VGEntrada = '77')then VGSaida := 'm';

if(VGEntrada = '78')then VGSaida := 'n';

if(VGEntrada = '79')then VGSaida := 'o';

if(VGEntrada = '80')then VGSaida := 'p';

if(VGEntrada = '81')then VGSaida := 'q';

if(VGEntrada = '82')then VGSaida := 'r';

if(VGEntrada = '83')then VGSaida := 's';

if(VGEntrada = '84')then VGSaida := 't';

if(VGEntrada = '85')then VGSaida := 'u';

if(VGEntrada = '86')then VGSaida := 'v';

if(VGEntrada = '87')then VGSaida := 'w';

if(VGEntrada = '88')then VGSaida := 'x';

if(VGEntrada = '89')then VGSaida := 'y';

if(VGEntrada = '90')then VGSaida := 'z';

if(VGEntrada = '91')then VGSaida := '{';

if(VGEntrada = '92')then VGSaida := '|';

if(VGEntrada = '93')then VGSaida := '}';

if(VGEntrada = '94')then VGSaida := '~';

if(VGEntrada = '95')then VGSaida := 'Â';

if(VGEntrada = '96')then VGSaida := 'Ä';

if(VGEntrada = '97')then VGSaida := 'Å';

if(VGEntrada = '98')then VGSaida := 'Æ';

if(VGEntrada = '99')then VGSaida := 'Ç';

//--------------------------------------//

//--------------------------------------//

//--------------------------------------//

VLCodigoBarras := "Í" + VLCodigoBarras + VGSaida + "Î";

VLCodigoBarras;

apartir deste algoritimo será impresso um codigo de caracteres e numeros que jogado na fonte 128C gera o codigo de barras, porem eu preciso converter este codigo de barras em uma imagem para vinculala no relatório!

Link para o comentário
Compartilhar em outros sites

  • 0
apartir deste algoritimo será impresso um codigo de caracteres e numeros que jogado na fonte 128C gera o codigo de barras, porem eu preciso converter este codigo de barras em uma imagem para vinculala no relatório!

onde aparece o código de barras quando ele é gerado ?

Link para o comentário
Compartilhar em outros sites

  • 0

Jhonas Muito Obrigado pela atenção,

Consegui parte da solução que no momento é o suficiente,

procedure convTextOut(CV: TCanvas; const sText: String; x, y, angle:integer);
  var
    LogFont: TLogFont;
    SaveFont: TFont;
  begin
    CV.Font.Name := 'Code 128';
    CV.Font.Size := 80;
    SaveFont := TFont.Create;
    SaveFont.Assign(CV.Font);
    GetObject(SaveFont.Handle, sizeof(TLogFont), @LogFont);
    with LogFont do
    CV.Font.Handle := CreateFontIndirect(LogFont);
    SetBkMode(CV.Handle, TRANSPARENT);
    CV.TextOut(x, y, sText);
    CV.Font.Assign(SaveFont);
    SaveFont.Free;
  end;

procedure TForm1.Button1Click(Sender: TObject);
  var
    VLCodigoBarras: String;
  begin
    VLCodigoBarras := '01234567890123456789012345';
    Canvas.Font.Name := 'Code 128';
    Canvas.Font.Size := 10;
    convTextOut(Canvas,VLCodigoBarras,50,170,0);

  end;

procedure TForm1.Button2Click(Sender: TObject);
  begin
    Canvas.Font.Name := 'Code 128';
    Canvas.Font.Size := 32;
    convTextOut(Image1.Canvas, Edit1.Text, 3, 0, 0);
    Image1.Picture.SaveToFile('E:\Projetos\Codigo de Barras Imagens\TesteGeraImagem\ImagemText\TESTE2.bmp');
  end;
end.

Apartir da fonte ele salva um picture, na realidade não preciso que ele exporte direto para o relatório só preciso que ele gere a imagem e depois com o Crystal eu referencio,

se notar o tamanho da fonte está 80.... e esse é o motivo da resolução não ter sido total, pois se eu jogar uma fonte menor, o o delphi salva a imagem mais a qualidade fica muito baixa o ideal da fonte seria 32 a 36 maior que isso a impressora não lê e tenho que corrigir o tamanho no cristal, se alguém puder me ajudar com isso, preciso que a qualidade seja meior mesmo com a fonte um pouco menor,

Se alguém já tiver em código, e puder me mandar explicando como insere e tal, faz 3 dias que eu estou mexendo com delphi to todo confundido, so tinha programado em C e muito pucom em Java, então com é veterano ai sabe o que eu to passando ;D

Abraço a todos e muito obrigado pela atenção!

Link para o comentário
Compartilhar em outros sites

  • 0

outra sugestão para salvar a imagem

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, RxGIF;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    procedure SaveAsBmp(fileName: TFileName);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  LogPal = record
  lpal : TLogPalette; 
  dummy:Array[0..255] of TPaletteEntry; 
  end;

procedure TForm1.SaveAsBmp(fileName: TFileName);
var
  Source: TComponent;
  SysPal : LogPal;
  tempCanvas: TCanvas;
  sourceRect, destRect: TRect;
  image2save: TImage;
  notUsed: HWND;
begin
  tempCanvas := TCanvas.Create;
  try
    tempCanvas.Handle := GetDeviceContext(notUsed);
    image2save:=TImage.create(self);

    try
      with image2save do
      begin
        Height := Self.Height;
        Width :=  Self.Width;
        destRect := Rect(0,0,Width,Height);
        sourceRect := destRect;
        Canvas.CopyRect(destRect,tempCanvas,sourceRect);
        SysPal.lPal.palVersion:=$300;
        SysPal.lPal.palNumEntries:=256;
        GetSystemPaletteEntries(tempCanvas.Handle,0,256,SysPal.lpal.palPalEntry);
        Picture.Bitmap.Palette:= CreatePalette(Syspal.lpal);

      end;
      image2save.Picture.SaveToFile(fileName);
    finally
     image2save.Free;
    end;
  finally
    tempCanvas.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   SaveAsBmp('c:\teste.bmp');
end;

end.

OBS: Este código gera uma imagem completa da tela, mas é possivel recortar uma coordenada especifica

abraço

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...