Lazbarcode 3of9 - half barcode lazarus / 21-General ---------------------------------------------------------------------- Int3g3r · 2025-05-19 07:54 Hello I am trying to generate a barcode with Lazbarcode (3of9). As I am saving this to a database I don't need to see the barcode element on the form. So I have put it on a PageControl and I will hide it. About the problem: If the barcode is not visible, only the "half" barcode is shown in the picture. Can someone explain to me what is going on here? How can I work around this? (see attamchents, Lazarus 3.6, FPC 3.2.2, x86_64-win64) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TformMain.btnGenerateClick(Sender: TObject);var  R: TRect;begin  barcode.Text:= RandomRange(1111111111,9999999999).ToString;  barcode.AutoSize:= true;  barcode.AdjustSize;  barcode.Generate;   FreeAndNil(barcodeImage);  barcodeImage := TBitmap.Create;  R := Rect(0,0,barcode.Width,barcode.Height);  barcodeImage.SetSize(barcode.Width,barcode.Height);  barcodeImage.Canvas.Brush.Color:= clWhite;  barcodeImage.Canvas.FillRect(R);  barcode.PaintOnCanvas(barcodeImage.Canvas, R);   bgImage.Picture.Assign(barcodeImage);end; Regards  Int3g3r ---------------------------------------------------------------------- paule32 · 2025-05-19 08:59 you could place a TScrollBox onto a TabSheet Page with Align := alClient; - also TabSheet is the Parent of TScrollBox, and within this ScrollBox, you add your Elements. ---------------------------------------------------------------------- paweld · 2025-05-19 09:55 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TformMain.Button1Click(Sender: TObject);var  b39: TBarcode3of9;  ms: TMemoryStream;begin  ms := TMemoryStream.Create;  b39 := TBarcode3of9.Create(nil);  b39.Text := RandomRange(1111111111,9999999999).ToString;  b39.Generate;  b39.SaveToStream(ms);  b39.Free;  ms.Position := 0;  bgImage.Picture.LoadFromStream(ms);  ms.Free;end; ---------------------------------------------------------------------- wp · 2025-05-19 10:17 IIRC, the barcode components in the LazBarcode package do some final sizing calculations during the painting process. Therefore, when the barcode is not visible, it is not drawn and the final size is not available. Your idea is to draw to a bitmap, but you need the size first to dimension the bitmap - a hen/egg problem... But you can save the barcode to a stream as a bitmap where you do not explicitely have to create a TBitmap instance (TBarcode.SaveToStream(stream, TBitmap)), and this works: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TformMain.Button1Click(Sender: TObject);var  stream: TMemoryStream;begin  barcode.Text:='0123456789'; // RandomRange(1111111111,9999999999).ToString;  barcode.Generate;  stream := TMemoryStream.Create;  try    barcode.SaveToStream(stream, TBitmap);    stream.Position := 0;    bgImage.Picture.LoadFromStream(stream);  finally    stream.Free;  end;end; This is even possible when you hide the barcode - this way you do not need to "hide" in on a pagecontrol . Since you do not want to see the barcode you could also try the TFPDrawBarcode with comes with FPC in fcl-image; you would not have to install a third-party package this way... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program demo_3of9;uses  Types, fpImage, fpBarCode, fpImgBarCode, fpWritePng;const  HEIGHT = 60;  NUMERIC_TEXT = '0123456789';  ENCODING = be39;    // or be39Extended?  UNIT_WIDTH = 2;  WEIGHT = 4;  FILE_NAME = '3of9.png';var  barcode: TFPDrawBarcode;  width: Integer;begin  barcode := TFPDrawBarcode.Create;  try    barcode.Encoding := ENCODING;    barcode.UnitWidth := UNIT_WIDTH;    barcode.Weight := WEIGHT;    barcode.Text := NUMERIC_TEXT;    width := barcode.CalcWidth;    barcode.Rect := Rect(0, 0, width, HEIGHT);    barcode.Image := TFPCompactImgGray8Bit.Create(barcode.Rect.Width, barcode.Rect.Height);    try      if barcode.Draw then      begin      barcode.Image.SaveToFile(FILE_NAME);        WriteLn('Saved to file ', FILE_NAME);      end else        WriteLn('Error generating barcode.');    finally      barcode.Image.Free;    end;  finally    barcode.Free;  end;end. [EDIT] paweld was faster than me. ---------------------------------------------------------------------- Int3g3r · 2025-05-19 12:23 Thanks to everyone for their help. Many thanks for the explanation.  Regards Int3g3r