SQL Server Requires Chilkat v11.7.0+
SQL Server
QR Code Colors and Transparent Background
See more QR Code Examples
Demonstrates colored QR codes. render.foreground is the color of the dark modules and render.background the color behind them, each as #RRGGBB. Either can instead be an object with a color and an opacity from 0 to 1, and a background opacity of 0 gives a PNG with a transparent background to place over a page or a design. Readers need contrast: keep the modules clearly darker than whatever ends up behind them.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 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 @fmt int
EXEC @hr = sp_OACreate 'Chilkat.Formats', @fmt OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @jsonOut int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonOut OUT
-- Dark blue modules on a pale yellow background.
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'render.moduleSize', 6
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'render.foreground', '#1B3A6B'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'render.background', '#FFF8DC'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.path', 'qa_output/qr_blue.png'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'output.overwrite', 1
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.return', 'none'
EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json, @jsonOut
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
EXEC @hr = sp_OADestroy @json
RETURN
END
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'outputs[0].path'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'outputs[0].byteCount'
PRINT 'colored: ' + @sTmp0 + ', ' + @iTmp0 + ' bytes'
-- The image written to qa_output/qr_blue.png:
--
-- The same modules on a fully transparent background.
DECLARE @json2 int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json2 OUT
EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/'
EXEC sp_OAMethod @json2, 'UpdateInt', @success OUT, 'render.moduleSize', 6
EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'render.foreground', '#1B3A6B'
EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'render.background.color', '#FFFFFF'
EXEC sp_OAMethod @json2, 'UpdateNumber', @success OUT, 'render.background.opacity', '0'
EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'output.path', 'qa_output/qr_transparent.png'
EXEC sp_OAMethod @json2, 'UpdateBool', @success OUT, 'output.overwrite', 1
EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'output.return', 'none'
EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json2, @jsonOut
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @json2
RETURN
END
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'outputs[0].path'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'outputs[0].byteCount'
PRINT 'transparent: ' + @sTmp0 + ', ' + @iTmp0 + ' bytes'
-- qa_output/qr_transparent.png, placed here over a checkerboard and over a colored page
-- to show that whatever is behind the image shows through:
--
-- Sample output:
-- colored: qa_output/qr_blue.png, 1345 bytes
-- transparent: qa_output/qr_transparent.png, 1377 bytes
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @json2
END
GO