Leadtools.Barcode Namespace > BarcodeWriter Class : CalculateBarcodeDataBounds Method |
public void CalculateBarcodeDataBounds( LeadRect writeBounds, int xResolution, int yResolution, BarcodeData data, IBarcodeWriteOptions options )
'Declaration Public Sub CalculateBarcodeDataBounds( _ ByVal writeBounds As LeadRect, _ ByVal xResolution As Integer, _ ByVal yResolution As Integer, _ ByVal data As BarcodeData, _ ByVal options As IBarcodeWriteOptions _ )
'Usage Dim instance As BarcodeWriter Dim writeBounds As LeadRect Dim xResolution As Integer Dim yResolution As Integer Dim data As BarcodeData Dim options As IBarcodeWriteOptions instance.CalculateBarcodeDataBounds(writeBounds, xResolution, yResolution, data, options)
public void CalculateBarcodeDataBounds( LeadRect writeBounds, int xResolution, int yResolution, BarcodeData data, IBarcodeWriteOptions options )
function Leadtools.Barcode.BarcodeWriter.CalculateBarcodeDataBounds( writeBounds , xResolution , yResolution , data , options )
public: void CalculateBarcodeDataBounds( LeadRect writeBounds, int xResolution, int yResolution, BarcodeData^ data, IBarcodeWriteOptions^ options )
Note: In LEADTOOLS for .NET, the equivalent to IBarcodeWriteOptions is BarcodeWriteOptions, also the equivalent to Leadtools.LeadRect is Leadtools.Forms.LogicalRectangle.
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Forms Imports Leadtools.Barcode Imports Leadtools.ImageProcessing Public Sub BarcodeWriter_CalculateBarcodeDataBoundsExample() Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "MyQRBarcode.tif") Dim engine As New BarcodeEngine() Dim writer As BarcodeWriter = engine.Writer ' Create the QR barcode data, we will use the default but you change it ' if needed Dim barcode As QRBarcodeData = DirectCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR), QRBarcodeData) ' Change the X Module to be 0.05 inches Dim options As QRBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.QR), QRBarcodeWriteOptions) options.XModule = 50 ' Calculate the size of the barcode with these options Dim resolution As Integer = 300 writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, barcode, options) ' Now create an image with the barcode size Dim pixels As LeadRect = barcode.Bounds.ToRectangle(resolution, resolution) Using image As RasterImage = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)) ' Write the barcode writer.WriteBarcode(image, barcode, options) ' Save the image to disk Using codecs As New RasterCodecs() codecs.Save(image, imageFileName, RasterImageFormat.CcittGroup4, 1) End Using End Using End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
using Leadtools; using Leadtools.Codecs; using Leadtools.Forms; using Leadtools.Barcode; using Leadtools.ImageProcessing; public void BarcodeWriter_CalculateBarcodeDataBoundsExample() { string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyQRBarcode.tif"); BarcodeEngine engine = new BarcodeEngine(); BarcodeWriter writer = engine.Writer; // Create the QR barcode data, we will use the default but you change it // if needed QRBarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as QRBarcodeData; // Change the X Module to be 0.05 inches QRBarcodeWriteOptions options = writer.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeWriteOptions; options.XModule = 50; // Calculate the size of the barcode with these options int resolution = 300; writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, barcode, options); // Now create an image with the barcode size LeadRect pixels = barcode.Bounds.ToRectangle(resolution, resolution); using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))) { // Write the barcode writer.WriteBarcode(image, barcode, options); // Save the image to disk using(RasterCodecs codecs = new RasterCodecs()) { codecs.Save(image, imageFileName, RasterImageFormat.CcittGroup4, 1); } } } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
using Leadtools; using Leadtools.Codecs; using Leadtools.Barcode; using Leadtools.ImageProcessing; public async Task BarcodeWriter_CalculateBarcodeDataBoundsExample() { string imageFileName = @"MyQRBarcode.tif"; BarcodeEngine engine = new BarcodeEngine(); BarcodeWriter writer = engine.Writer; // Create the QR barcode data, we will use the default but you change it // if needed BarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR); // Change the X Module to be 0.05 inches QRBarcodeWriteOptions options = writer.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeWriteOptions; options.XModule = 50; // Calculate the size of the barcode with these options int resolution = 300; writer.CalculateBarcodeDataBounds(LeadRectHelper.Empty, resolution, resolution, barcode, options); // Now create an image with the barcode size LeadRect pixels = barcode.Bounds; using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColorHelper.FromKnownColor(RasterKnownColor.White))) { // Write the barcode writer.WriteBarcode(image, barcode, options); // Save the image to disk using(RasterCodecs codecs = new RasterCodecs()) { StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(imageFileName); await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.CcittGroup4, 1); } } }
using Leadtools; using Leadtools.Codecs; using Leadtools.Forms; using Leadtools.Barcode; using Leadtools.ImageProcessing; using Leadtools.Examples; public void BarcodeWriter_CalculateBarcodeDataBoundsExample(Stream outStream) { BarcodeEngine engine = new BarcodeEngine(); BarcodeWriter writer = engine.Writer; // Create the QR barcode data, we will use the default but you change it // if needed QRBarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as QRBarcodeData; // Change the X Module to be 0.05 inches QRBarcodeWriteOptions options = writer.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeWriteOptions; options.XModule = 50; // Calculate the size of the barcode with these options int resolution = 300; writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, barcode, options); // Now create an image with the barcode size LeadRect pixels = barcode.Bounds.ToRectangle(resolution, resolution); using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))) { // Write the barcode writer.WriteBarcode(image, barcode, options); // Save the image to disk RasterCodecs codecs = new RasterCodecs(); codecs.Save(image, outStream, RasterImageFormat.CcittGroup4, 1); } }
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Forms Imports Leadtools.Barcode Imports Leadtools.ImageProcessing Public Sub BarcodeWriter_CalculateBarcodeDataBoundsExample(ByVal outStream As Stream) Dim engine As BarcodeEngine = New BarcodeEngine() Dim writer As BarcodeWriter = engine.Writer ' Create the QR barcode data, we will use the default but you change it ' if needed Dim barcode As QRBarcodeData = TryCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR), QRBarcodeData) ' Change the X Module to be 0.05 inches Dim options As QRBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.QR), QRBarcodeWriteOptions) options.XModule = 50 ' Calculate the size of the barcode with these options Dim resolution As Integer = 300 writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, barcode, options) ' Now create an image with the barcode size Dim pixels As LeadRect = barcode.Bounds.ToRectangle(resolution, resolution) Using image As RasterImage = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)) ' Write the barcode writer.WriteBarcode(image, barcode, options) ' Save the image to disk Dim codecs As RasterCodecs = New RasterCodecs() codecs.Save(image, outStream, RasterImageFormat.CcittGroup4, 1) End Using End Sub