Cannot set barcode image size with specific DPI

Hello Aspose Team,

i need to generate 2D barcode ( DataMatrix) with following specifications:

  • Image Width 213
  • Image Height 213
  • X Resolution 600
  • Y Resolution 600
  • Resolution Unit inches
  • see ImageExamples.zip -> source.tiff

I’am using Aspose.BarCode library for dotnet core v21.2.0

Examples:
ImageExamples.zip (1.9 KB)

source.tiff ExifTool output:

ExifTool Version Number         : 12.05
File Name                       : source.tiff
Directory                       : .
File Size                       : 5.8 kB
File Modification Date/Time     : 2021:03:17 09:11:47+01:00
File Access Date/Time           : 2021:03:17 09:11:47+01:00
File Inode Change Date/Time     : 2021:03:17 11:03:49+01:00
File Permissions                : rw-rw-r--
File Type                       : TIFF
File Type Extension             : tif
MIME Type                       : image/tiff
Exif Byte Order                 : Little-endian (Intel, II)
Image Width                     : 213
Image Height                    : 213
Bits Per Sample                 : 1
Compression                     : Uncompressed
Photometric Interpretation      : BlackIsZero
Strip Offsets                   : 8
Orientation                     : Horizontal (normal)
Rows Per Strip                  : 155344
Strip Byte Counts               : 5751
X Resolution                    : 600
Y Resolution                    : 600
Planar Configuration            : Chunky
Resolution Unit                 : inches
Image Size                      : 213x213
Megapixels                      : 0.045

My Source Code:

BarcodeGenerator  generator = new BarcodeGenerator (EncodeTypes.DataMatrix, "10014490");
generator.Parameters.Resolution = 600f;
generator.Parameters.Barcode.Padding.Top.Millimeters = 0f;
generator.Parameters.Barcode.Padding.Bottom.Millimeters = 0f;
generator.Parameters.Barcode.Padding.Left.Millimeters = 0f;
generator.Parameters.Barcode.Padding.Right.Millimeters = 0f;
generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None;
generator.Parameters.AutoSizeMode = AutoSizeMode.None;
generator.Parameters.ImageHeight.Inches = 213;
generator.Parameters.ImageWidth.Inches = 213;
generator.Save("output.tiff", BarCodeImageFormat.Tiff);

output.tiff ExifTool output:

ExifTool Version Number         : 12.05
File Name                       : output.tiff
Directory                       : .
File Size                       : 110 kB
File Modification Date/Time     : 2021:03:17 10:59:09+01:00
File Access Date/Time           : 2021:03:17 10:56:55+01:00
File Inode Change Date/Time     : 2021:03:17 10:59:09+01:00
File Permissions                : rw-rw-r--
File Type                       : TIFF
File Type Extension             : tif
MIME Type                       : image/tiff
Exif Byte Order                 : Little-endian (Intel, II)
Image Width                     : 168
Image Height                    : 168
Bits Per Sample                 : 8 8 8 8
Compression                     : Uncompressed
Photometric Interpretation      : RGB
Strip Offsets                   : 8
Orientation                     : Horizontal (normal)
Samples Per Pixel               : 4
Rows Per Strip                  : 672
Strip Byte Counts               : 112896
Planar Configuration            : Chunky
Image Size                      : 168x168
Megapixels                      : 0.028

For me its impossible to reach desired result.
Can you please explain me, how to configure BarcodeGenerator class to get desired result?

Thank you & best regards

Matthias

You code has two problems. First, ImageHeight/ImageWidth can be use only with AutoSizeMode.Nearest and AutoSizeMode.Interpolation. And you can have code like this

BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.DataMatrix, “10014490”);
generator.Parameters.Resolution = 600f;
generator.Parameters.Barcode.Padding.Top.Millimeters = 0f;
generator.Parameters.Barcode.Padding.Bottom.Millimeters = 0f;
generator.Parameters.Barcode.Padding.Left.Millimeters = 0f;
generator.Parameters.Barcode.Padding.Right.Millimeters = 0f;
generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None;
generator.Parameters.AutoSizeMode = Aspose.BarCode.Generation.AutoSizeMode.Nearest;
// generator.Parameters.AutoSizeMode = Aspose.BarCode.Generation.AutoSizeMode.Interpolation;
generator.Parameters.ImageHeight.Inches = 10;
generator.Parameters.ImageWidth.Inches = 10;
generator.Save(“output.tiff”, BarCodeImageFormat.Tiff);

The second problem is too big image. 213x213 inches image with 600 dpi consists from (213*600)^2 pixels, and because one pixel is stored in 4 bytes(32 bits) it requires 65 Gb of memory. But Windows cannot operate with image that uses more than 4 Gb of memory.

1 Like

Thank you very much alexander, you helped me alot!