Jump to content

TCanvas in TUniImage


belo

Recommended Posts

In an application using the VCL TCanvas to generate a BarCode with a TImage component (Image1.Canvas), like the example below..
 
There is a property in TUniImage Canvas, and has no equivalent method TUniCanvas the TCanvas.Polygon.
 
How can I adapt the example below to UniGui?
 
procedure TMainForm.CriaCodigo(Cod: string; Imagem: TCanvas);
const
  digitos: array ['0' .. '9'] of string[5] = ('00110', '10001', '01001',
    '11000', '00101', '10100', '01100', '00011', '10010', '01010');
var
  Numero: string;
  Cod1: array [1 .. 1000] of Char;
  Cod2: array [1 .. 1000] of Char;
  Codigo: array [1 .. 1000] of Char;
  Digito: string;
  c1, c2: Integer;
  X, Y, z, h: LongInt;
  a, b, c, d: TPoint;
  I: Boolean;
begin
  Numero := Cod;
  for X := 1 to 1000 do
  begin
    Cod1[X] := #0;
    Cod2[X] := #0;
    Codigo[X] := #0;
  end;
  c1 := 1;
  c2 := 1;
  X := 1;
  for Y := 1 to Length(Numero) div 2 do
  begin
    Digito := digitos[Numero[X]];
    for z := 1 to 5 do
    begin
      Cod1[c1] := Digito[z];
      inc(c1);
    end;
    Digito := digitos[Numero[X + 1]];
    for z := 1 to 5 do
    begin
      Cod2[c2] := Digito[z];
      inc(c2);
    end;
    inc(X, 2);
  end;
  Y := 5;
  Codigo[1] := '0';
  Codigo[2] := '0';
  Codigo[3] := '0';
  Codigo[4] := '0'; 
  for X := 1 to c1 - 1 do
  begin
    Codigo[Y] := Cod1[X];
    inc(Y);
    Codigo[Y] := Cod2[X];
    inc(Y);
  end;
  Codigo[Y] := '1'; 
  inc(Y);
  Codigo[Y] := '0';
  inc(Y);
  Codigo[Y] := '0';
  Imagem.Pen.Width := 1;
  Imagem.Brush.Color := ClWhite;
  Imagem.Pen.Color := ClWhite;
  a.X := 1;
  a.Y := 0;
  b.X := 1;
  b.Y := 50;
  c.X := 2000;
  c.Y := 50;
  d.X := 2000;
  d.Y := 0;
  Imagem.Polygon([a, b, c, d]);
  Imagem.Brush.Color := ClBlack;
  Imagem.Pen.Color := ClBlack;
  X := 0;
  I := True;
  for Y := 1 to 1000 do
  begin
    if Codigo[Y] <> #0 then
    begin
      if Codigo[Y] = '0' then
        h := 1
      else
        h := 3;
      a.X := X;
      a.Y := 0;
      b.X := X;
      b.Y := 50;
      c.X := X + h - 1;
      c.Y := 50;
      d.X := X + h - 1;
      d.Y := 0;
      if I then
        Imagem.Polygon([a, b, c, d]);
      I := not(I);
      X := X + h;
    end;
  end;
end;

// here call the procedure
CriaCodigo(cdsCOD_BAR.FieldByName('COD_BARRA').AsString, Image1.Canvas);

 

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...