From c9fc88a06eb085518d25ab9cc2d43d3d8bf0f52c Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 26 Jul 2016 17:40:08 +0000 Subject: [PATCH] lazbarcodes: Add method to copy a barcode image to clipboard. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5038 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/lazbarcodes/src/ubarcodes.pas | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/components/lazbarcodes/src/ubarcodes.pas b/components/lazbarcodes/src/ubarcodes.pas index f7df5f41c..0d98e4221 100644 --- a/components/lazbarcodes/src/ubarcodes.pas +++ b/components/lazbarcodes/src/ubarcodes.pas @@ -39,6 +39,7 @@ protected public constructor Create(AOwner: TComponent); override; destructor Destroy; override; + procedure CopyToClipboard(AWidth: Integer = -1; AHeight: Integer = -1); procedure PaintOnCanvas(const aTargetCanvas: TCanvas; const aRect: TRect); procedure Generate; virtual; abstract; published @@ -124,6 +125,9 @@ procedure Register; implementation +uses + clipbrd; + procedure Register; begin {$I tbarcodeqr.lrs} @@ -296,6 +300,24 @@ begin inherited Destroy; end; +procedure TLazBarcodeCustomBase.CopyToClipboard(AWidth, AHeight: Integer); +var + bmp: TBitmap; +begin + if AWidth = -1 then AWidth := Width; + if AHeight = -1 then AHeight := Height; + bmp := TBitmap.Create; + try + bmp.SetSize(AWidth, AHeight); + bmp.Canvas.Brush.Color := clWhite; + bmp.Canvas.FillRect(0, 0, AWidth, AHeight); + PaintOnCanvas(bmp.Canvas, Rect(0, 0, AWidth, AHeight)); + Clipboard.Assign(bmp); + finally + bmp.Free; + end; +end; + procedure TLazBarcodeCustomBase.PaintOnCanvas(const aTargetCanvas: TCanvas; const aRect: TRect); begin