Recent

Author Topic: Barcodes in BGRABitmap  (Read 2032 times)

99Percent

  • Full Member
  • ***
  • Posts: 154
Barcodes in BGRABitmap
« on: December 05, 2014, 04:18:44 am »
I am having trouble getting a barcode in a TBGRABitmap canvas.

I am using the barcode library.

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  Bitmap,Photo : TBGRABitmap;
  Barcode : TBarcode;
begin
    Bitmap := TBGRABitmap.Create(661,1028,BGRAPixelTransparent);
     Photo :=TBGRABitmap.Create('somepicture.jpg');
     Barcode:=TBarcode.Create(self);
    try
       with Bitmap do begin
         StretchPutImage(Rect(40,400,440,830),Photo,dmDrawWithTransparency,255);
         FontHeight:=40;
         FontAntialias:=True;
         FontStyle:= [fsBold];
         TextOut(240,950,'Name Last Name',BGRABlack,taCenter);
       end;
       with Barcode do begin
         Typ:=bcCode128A;
         Height:=80;
         Modul:=3;
         Text:='^01234';
         Barcode.
         Top:=850;
         Left:=40+((400-Width) div 2);
         DrawBarcode(Bitmap.Canvas);
       end;
         Bitmap.SaveToFile('credencial.png');
       Image1.Picture.Bitmap.Assign(Bitmap);
     finally
       Bitmap.Free;
       Photo.Free;
       Barcode.Free;
  end;
end;

It works fine in Linux but on Windows the black lines of the barcode are gone, only the white lines show. I have tried drawing a polygon directly to canvas and if I use any color except black it appears fine. Only the black color seems to be causing this problem. What am I missing?

circular

  • Hero Member
  • *****
  • Posts: 3024
    • Personal webpage
Re: Barcodes in BGRABitmap
« Reply #1 on: December 05, 2014, 04:00:31 pm »
The black color (clBlack) is used to specify a transparent color. To have a black color, you need to use clBlackOpaque constant instead.

Alternatively, if you cannot change the color of the bar code, you can use Bitmap.AlphaFill to set the alpha channel to 255 afterwards in the desired area.
Conscience is the debugger of the mind