SQL Server Requires Chilkat v11.7.0+
SQL Server
Measure a QR Code without Rendering It
See more QR Code Examples
Demonstrates the measure operation, which does everything generate does except draw the image. It reports the version chosen and the exact size the image would have, which is useful for laying out a page or a label before any image is made. Unlike generate, a code that does not fit the limits is not a failure for measure: the call succeeds, fits is false, and reasons[] says why.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @iTmp1 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @sTmp1 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/barcode_overview.asp'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'render.moduleSize', 8
DECLARE @fmt int
EXEC @hr = sp_OACreate 'Chilkat.Formats', @fmt OUT
DECLARE @jsonOut int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonOut OUT
EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'measure', @json, @jsonOut
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
RETURN
END
EXEC sp_OAMethod @jsonOut, 'BoolOf', @iTmp0 OUT, 'fits'
PRINT 'fits: ' + @iTmp0
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
PRINT 'QR version: ' + @iTmp0
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'measurements[0].canvasWidth'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp1 OUT, 'measurements[0].canvasHeight'
PRINT 'image would be: ' + @iTmp0 + ' x ' + @iTmp1 + ' pixels'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'measurements[0].symbolWidth'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp1 OUT, 'measurements[0].symbolX'
PRINT 'symbol: ' + @iTmp0 + ' pixels wide at x = ' + @iTmp1
-- Would it fit in a space 200 pixels wide?
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'render.maxWidth', 200
EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'measure', @json, @jsonOut
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
RETURN
END
EXEC sp_OAMethod @jsonOut, 'BoolOf', @iTmp0 OUT, 'fits'
PRINT 'within 200 pixels, fits: ' + @iTmp0
EXEC sp_OAMethod @jsonOut, 'BoolOf', @iTmp0 OUT, 'fits'
IF @iTmp0 = 0
BEGIN
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'reasons[0].code'
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp1 OUT, 'reasons[0].message'
PRINT 'reason: ' + @sTmp0 + ' (' + @sTmp1 + ')'
END
-- What measure reported, drawn as a diagram. The measure operation itself makes no image:
--
-- Sample output:
-- fits: True
-- QR version: 4
-- image would be: 328 x 328 pixels
-- symbol: 264 pixels wide at x = 32
-- within 200 pixels, fits: False
-- reason: noFit (exceedsMaxWidth)
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
END
GO