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
This commit is contained in:
wp_xxyyzz
2020-08-06 10:26:14 +00:00
parent 8563d58898
commit 5b34810a57
3 changed files with 30 additions and 3 deletions

View File

@ -14,7 +14,7 @@
</SearchPaths> </SearchPaths>
</CompilerOptions> </CompilerOptions>
<Description Value="Provides barcode 1D and 2D generation based in the 'C' zint library."/> <Description Value="Provides barcode 1D and 2D generation based in the 'C' zint library."/>
<Version Major="1" Release="3"/> <Version Major="1" Release="4"/>
<Files Count="1"> <Files Count="1">
<Item1> <Item1>
<Filename Value="..\src\ubarcodes.pas"/> <Filename Value="..\src\ubarcodes.pas"/>

View File

@ -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 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 this gives the possibility to include ZINT library in own products or link against it from
own software."/> own software."/>
<Version Major="1" Release="3"/> <Version Major="1" Release="4"/>
<Files Count="9"> <Files Count="9">
<Item1> <Item1>
<Filename Value="..\src\zint.pp"/> <Filename Value="..\src\zint.pp"/>

View File

@ -42,6 +42,9 @@ public
procedure CopyToClipboard(AWidth: Integer = -1; AHeight: Integer = -1); procedure CopyToClipboard(AWidth: Integer = -1; AHeight: Integer = -1);
procedure PaintOnCanvas(const aTargetCanvas: TCanvas; const aRect: TRect); procedure PaintOnCanvas(const aTargetCanvas: TCanvas; const aRect: TRect);
procedure Generate; virtual; abstract; procedure Generate; virtual; abstract;
procedure SaveToFile(const AFileName: String;
AClass: TFPImageBitmapClass = nil;
AWidth: Integer = -1; AHeight: Integer = -1);
published published
property StrictSize: Boolean read GetStrictSize write SetStrictSize; property StrictSize: Boolean read GetStrictSize write SetStrictSize;
property BackgroundColor: TColor read GetBackgroundColor write SetBackgroundColor default clWhite; property BackgroundColor: TColor read GetBackgroundColor write SetBackgroundColor default clWhite;
@ -307,7 +310,8 @@ begin
FBackgroundColor:=clWhite; FBackgroundColor:=clWhite;
FForegroundColor:=clBlack; FForegroundColor:=clBlack;
FStrictSize:=true; FStrictSize:=true;
SetInitialBounds(0,0,88,88); Width := 88;
Height := 88;
end; end;
destructor TLazBarcodeCustomBase.Destroy; destructor TLazBarcodeCustomBase.Destroy;
@ -395,6 +399,29 @@ begin
end; end;
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; function TLazBarcodeCustomText.GetText: UTF8String;
begin begin
Result:=FText; Result:=FText;