Recent

Author Topic: LazBarCode 2D Image Saving  (Read 2641 times)

havoc

  • Newbie
  • Posts: 4
LazBarCode 2D Image Saving
« on: February 19, 2019, 08:16:03 am »
Hi!

I need to have the 2D codes generated by LazBarCode 2D saved as an image file (.png preferred, but .jpg is OK) to incorporate into a report. Can someone please provide a sample code or point me in the right direction?

Thanks!

havoc

  • Newbie
  • Posts: 4
Re: LazBarCode 2D Image Saving [Resolved]
« Reply #1 on: February 19, 2019, 09:53:00 am »
Just found out that there's a CopyToClipboard function. So I just used it copy the resultant 2D barcode image to an Image component and save it to a file.

In case others might need it...

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. begin
  3.   BarcodeQR1.CopyToClipboard();
  4.   Image1.Picture.LoadFromClipboardFormat(CF_Bitmap);
  5.   if (SaveDialog1.Execute) then
  6.     Image1.Picture.SaveToFile(SaveDialog1.Filename);
  7. end;
  8.  

Cheers!


wp

  • Hero Member
  • *****
  • Posts: 11858
Re: LazBarCode 2D Image Saving
« Reply #2 on: February 19, 2019, 06:18:36 pm »
I just uploaded a new version 1.0.4 which provides a method for saving to graphic file:

Code: Pascal  [Select][+][-]
  1. procedure TLazBarcodeCustomBase.SaveToFile(const AFileName: String;
  2.   AClass: TFPImageBitmapClass = nil; AWidth: Integer = -1; AHeight: Integer = -1);
  3.  
  4. QRCode.SaveToFile('test.bmp'); // ---> saves to a bmp file
  5. QRCode.SaveToFile('test.png', TPortableNetworkgraphic); // --> saves to a png file
  6. QRCode.SaveToFile('test.jpg', TJpegImage, 200, 200);    // --> saves to a jpeg file of 200 x 200 pixels  

Find the download at https://sourceforge.net/projects/lazarus-ccr/files/LazBarcodes/lazbarcodes-1.0.4.zip/download; the new version also will be distributed via the OnlinePackageMangager shortly.

havoc

  • Newbie
  • Posts: 4
Re: LazBarCode 2D Image Saving
« Reply #3 on: February 20, 2019, 12:14:02 pm »
I just uploaded a new version 1.0.4 which provides a method for saving to graphic file:

Code: Pascal  [Select][+][-]
  1. procedure TLazBarcodeCustomBase.SaveToFile(const AFileName: String;
  2.   AClass: TFPImageBitmapClass = nil; AWidth: Integer = -1; AHeight: Integer = -1);
  3.  
  4. QRCode.SaveToFile('test.bmp'); // ---> saves to a bmp file
  5. QRCode.SaveToFile('test.png', TPortableNetworkgraphic); // --> saves to a png file
  6. QRCode.SaveToFile('test.jpg', TJpegImage, 200, 200);    // --> saves to a jpeg file of 200 x 200 pixels  

Find the download at https://sourceforge.net/projects/lazarus-ccr/files/LazBarcodes/lazbarcodes-1.0.4.zip/download; the new version also will be distributed via the OnlinePackageMangager shortly.

Awesome!

I've have been looking for a solution since December, and was already happy when I stumbled upon the TImage workaround.

Now I'm even happier that it comes built-in.

Thanks, wp!

 

TinyPortal © 2005-2018