From 5b34810a57bf1953eeafa91006619668b2b6e08c Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 6 Aug 2020 10:26:14 +0000 Subject: [PATCH] LazBarcodes: Add SaveToFile to save barcode images in graphics files. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7597 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../lazbarcodes/packages/lazbarcodes.lpk | 2 +- .../packages/lazbarcodes_runtimeonly.lpk | 2 +- components/lazbarcodes/src/ubarcodes.pas | 29 ++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/components/lazbarcodes/packages/lazbarcodes.lpk b/components/lazbarcodes/packages/lazbarcodes.lpk index 68d9b02bf..2d731422e 100644 --- a/components/lazbarcodes/packages/lazbarcodes.lpk +++ b/components/lazbarcodes/packages/lazbarcodes.lpk @@ -14,7 +14,7 @@ - + diff --git a/components/lazbarcodes/packages/lazbarcodes_runtimeonly.lpk b/components/lazbarcodes/packages/lazbarcodes_runtimeonly.lpk index c788e935f..569b9dd97 100644 --- a/components/lazbarcodes/packages/lazbarcodes_runtimeonly.lpk +++ b/components/lazbarcodes/packages/lazbarcodes_runtimeonly.lpk @@ -28,7 +28,7 @@ Change to BSD-license is done for backend and therefore for ZINT shared library the frontends and Qt4-backend the GPL is still valid. Since BSD-license is GPL-compatible this gives the possibility to include ZINT library in own products or link against it from own software."/> - + diff --git a/components/lazbarcodes/src/ubarcodes.pas b/components/lazbarcodes/src/ubarcodes.pas index 9cd8cec1f..4a1237722 100644 --- a/components/lazbarcodes/src/ubarcodes.pas +++ b/components/lazbarcodes/src/ubarcodes.pas @@ -42,6 +42,9 @@ public procedure CopyToClipboard(AWidth: Integer = -1; AHeight: Integer = -1); procedure PaintOnCanvas(const aTargetCanvas: TCanvas; const aRect: TRect); procedure Generate; virtual; abstract; + procedure SaveToFile(const AFileName: String; + AClass: TFPImageBitmapClass = nil; + AWidth: Integer = -1; AHeight: Integer = -1); published property StrictSize: Boolean read GetStrictSize write SetStrictSize; property BackgroundColor: TColor read GetBackgroundColor write SetBackgroundColor default clWhite; @@ -307,7 +310,8 @@ begin FBackgroundColor:=clWhite; FForegroundColor:=clBlack; FStrictSize:=true; - SetInitialBounds(0,0,88,88); + Width := 88; + Height := 88; end; destructor TLazBarcodeCustomBase.Destroy; @@ -395,6 +399,29 @@ begin end; end; +procedure TLazBarcodeCustomBase.SaveToFile(const AFileName: String; + AClass: TFPImageBitmapClass = nil; + AWidth: Integer = -1; AHeight: Integer = -1); +var + bmp: TFPImageBitmap; +begin + if AClass = nil then + bmp := TBitmap.Create + else + bmp := AClass.Create; + if AWidth = -1 then AWidth := Width; + if AHeight = -1 then AHeight := Height; + try + bmp.SetSize(AWidth, AHeight); + bmp.Canvas.Brush.Color := clWhite; + bmp.Canvas.FillRect(0, 0, bmp.Width, bmp.Height); + PaintOnCanvas(bmp.Canvas, Rect(0, 0, bmp.Width, bmp.Height)); + bmp.SaveToFile(AFileName); + finally + bmp.Free; + end; +end; + function TLazBarcodeCustomText.GetText: UTF8String; begin Result:=FText;