Jump to content
wsian

Zint barcode studio zint.dll

Recommended Posts

Has anyone able to use latest zint.dll (v2.11) for printing barcode?

I'm only able to use up to v2.6.1 to get the barcode. Version beyond that will just print out a blank image.

Share this post


Link to post

managed to find Chet - C Header Translator for Delphi to translate zint.h to zint.pas.

With minimum adjustment, able to up and run the barcode with latest version.

Edited by wsian
  • Like 1

Share this post


Link to post
5 hours ago, wsian said:

managed to find Chet - C Header Translator for Delphi to translate zint.h to zint.pas.

With minimum adjustment, able to up and run the barcode with latest version.

Would you mind sharing this with the community?

Share this post


Link to post
2 hours ago, Stéphane Wierzbicki said:

Would you mind sharing this with the community?

It's in my awesome list (link in the signature)

  • Thanks 1

Share this post


Link to post

Download the latest zint.dll (v2.11) from here  https://sourceforge.net/projects/zint/

 

I'm only using ZBarcode_Encode_and_Buffer. If you need to use other function, please adjust the zint.pas accordingly.

Sample code as below:

procedure ZBarcode_To_Bitmap(symbol: PZint_Symbol; const ABitmap: TBitmap);
var
  SrcRGB: PRGBTriple;
  Row, RowWidth: Integer;
begin
  ABitmap.PixelFormat := pf24bit;
  ABitmap.SetSize(symbol.bitmap_width, symbol.bitmap_height);
  SrcRGB := Pointer(symbol.bitmap);
  RowWidth := symbol.bitmap_width * 3;

  for Row := 0 to symbol.bitmap_height - 1 do
  begin
    CopyMemory(ABitmap.ScanLine[Row], SrcRGB, RowWidth);
    Inc(SrcRGB, symbol.bitmap_width);
  end;

  SetBitmapBits(ABitmap.Handle, symbol.bitmap_width * symbol.bitmap_height * 3, symbol.bitmap);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  lvSymbol : Pzint_symbol;
  lvErrorNumber: Integer;
  lvData: UTF8String;
  lvBitMap: TBitmap;
  lvErrorText: string;

begin
  lvSymbol := ZBarcode_Create();
  if lvSymbol = nil then
    Exit;

  lvBitMap := TBitmap.Create;
  try
    lvSymbol.symbology:=  BARCODE_QRCODE; 
    lvSymbol.input_mode := DATA_MODE ;
    lvData := utf8string(Edit1.Text);

    lvErrorNumber := ZBarcode_Encode_and_Buffer(lvSymbol, PAnsiChar(lvData), Length(lvData), 0);
    if lvErrorNumber = 0 then
    begin
      ZBarcode_To_Bitmap(lvSymbol, lvBitMap);
      ZBarcode_Print(lvSymbol,0) ;

      Image1.Picture.Bitmap.Width := Image1.Width;
      Image1.Picture.Bitmap.Height := Image1.Height;
      Image1.Picture.Bitmap.Canvas.Brush.Color := clWhite;
      Image1.Picture.Bitmap.Canvas.FillRect(Rect(0, 0, Image1.Width, Image1.Height));
      Image1.Picture.Bitmap.Canvas.StretchDraw(Rect(10, 10, Image1.Width - 10, Image1.Height - 10), lvBitMap);

    end
    else
    begin
      Image1.Picture.Bitmap.Width := Image1.Width;
      Image1.Picture.Bitmap.Height := Image1.Height;
      Image1.Picture.Bitmap.Canvas.Brush.Color := clWhite;
      Image1.Picture.Bitmap.Canvas.FillRect(Rect(0, 0, Image1.Width, Image1.Height));
      lvErrorText := String(AnsiString(lvSymbol.errtxt));
      ShowMessage('barcode error:' + lvErrorText);
    end;


  finally
    lvBitMap.Free;
    lvBitMap := nil;
    ZBarcode_Delete(lvSymbol);
  end;
end;

 

zint.pas

Edited by wsian
  • Thanks 1

Share this post


Link to post

Alternately, you can use Zint-Barcode-Generator-for-Delphi by landrix (no dll needed).

Just that the last updated version has an issue. The linear barcode (code128 etc) has been squeezed to 1/3 or even 1/5 block height. Not sure when it will be corrected.

Edited by wsian
  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×