Skip to end of metadata
Go to start of metadata
  

Customize Barcode Image Resolution

What if developers need to set the resolution of their barcode images according to their custom settings? Well, Aspose.BarCode also addresses this issue and provides Resolution class that serves developers to customize the resolution of their barcode images in any way they want.Resolution class has three major properties:

  1. DpiX that is used to set Horizontal Resolution settings of the barcode image in Dot per inches (Dpi)
  2. DpiY that is used to set Vertical Resolution settings of the barcode image in Dot per inches (Dpi)
  3. Mode that is used to set the Resolution Mode of the barcode image

DpiX and DpiY propeties of Resolution class accept simple float values to configure horizontal and vertical resolutions. But, Mode property accepts one of the pre-defined values from ResolutionMode enumeration, which are listed below

Resolution Modes

Description

Graphics

Apply the resolution of the barcode image according to the resolution of the specified Graphics object

Customized

Apply the resolution of the barcode image according to the user defined DpiX and DpiY properties

Printer

Apply the resolution of the barcode image according to the resolution of the specified Printer

Developers can select any resolution mode from the list above using ResolutionMode enumeration. An example to generate a barcode image using customized resolution settings, is discussed below for a better understanding. Dpi is a measure of image resolution that specifies the number of dots that a printer or device (like a monitor) can display per linear inch. The higher the Dpi, the higher the resolution.

Set Size Unit for the Barcode Image

To change the measuring unit of the barcode image, developers can make use of GraphicsUnit property of any barcode class (BarCodeBuilder, BarCodeControl or BarCodeWebControl) provided by Aspose.BarCode. GraphicsUnit property accepts any pre-defined value in System.Drawing.GraphicsUnit enumeration. The pre-defined measuring units in GraphicsUnit enumeration are as follows:

Measuring Units

Description

Display

Specifies 1/75 inch as the unit of measure

Document

Specifies the document unit (1/300 inch) as the unit of measure

Inch

Specifies the inch as the unit of measure

Millimeter

Specifies the millimeter as the unit of measure

Pixel

Supported by the C++ Compact Framework. Specifies a device pixel as the unit of measure

Point

Specifies a printer's point (1/72 inch) as the unit of measure

World

Specifies the world unit as the unit of measure

The default size measurement unit for barcode image is Millimeter. An example is given below that changes the bar height of the barcode but the measuring unit being used for the bar height is Point.

Save Barcode Images to different Formats

Aspose.BarCode facilitates its developers to save the barcode images to most of the popular image formats. All barcode generating classes (BarCodeBuilder, BarCodeControl or BarCodeWebControl) provided by Aspose.BarCode, have a public method, Save. Save method takes an instance of System.Drawing.Imaging.ImageFormat class. Following image formats can be passed to Save method of the barcode class as an argument:

  • ImageFormat.Bmp
  • ImageFormat.Emf
  • ImageFormat.Exif
  • ImageFormat.Gif
  • ImageFormat.Icon
  • ImageFormat.Jpeg
  • ImageFormat.MemoryBmp
  • ImageFormat.Png
  • ImageFormat.Tiff
  • ImageFormat.Wmf

Developers can use any of the image format from the above list to create a barcode image in a desired image format. An example is given below about its usage. Aspose.BarCode for Java only supports Jpg, Gif, Png and Bmp.

Save Barcode Image to Streams

In our previous topics, we have studied that a barcode image can be saved to different image formats like Jpeg, Metafile, Tiff and Bitmap etc. But sometimes, developers may need to save the barcode image in the form of a Stream (as binary format). To fulfill this need, Aspose.BarCode offers its users to save a barcode image to a Stream by calling the Save method of BarCodeImage object, which is encapsulated in all barcode classes of Aspose.BarCode as a property.

An example is given below as a demonstration for the conversion of the barcode image into System.IO.MemoryStream (a kind of Stream to hold binary data) object . Save method of BarCodeImage takes an object of MemoryStream (which will store barcode image) and an instance of System.Drawing.Imaging.ImageFormat (that allows developers to specify barcode image format like Jpeg, Png, Gif, Metafile etc.).

Generate Barcode by Specifying Custom Image Size

Aspose.BarCode for C++ automatically adjusts the image size (width and height) according to the generated barcode’s size. But, you can also control the image size by specifying height and width of image using BarCodeBuilder.ImageHeight and ImageWidth properties. BarCodeBuilder.AutoSize should be set to false in order to customize the image size. In the below example, we will generate a Code39Standard barcode with customized height and width.

Print Barcode Image

Printing barcode image can be easily done with Aspose.BarCode for C++ with 3 lines of code.

  1. Specify printer’s name using BarCodeBuilder.PrinterName property. If this property is not set, then the Windows default printer is used.
  2. Call BarCodeBuilder.Print() method to print the barcode.

Below is the code snippet to create and print a Code128 barcode

Specify Border Types for ITF14 Barcode

BarCodeBuilder class allow us to specify the Border type of the barcode ITF14 Symbology. Let's experience this feature and know how it works.

Specifying Border Type for ITF14 Barcode

Developers can customize the border type of the ITF14 barcode image using ITF14BorderType property of the BarCodeBuilder class. Aspose.BarCode offers some built-in ITF14 barcode border types that are contained in an enumeration named as ITF14BorderType. Developers can select a desired border type from this enumeration and assign it to the ITF14BorderType property of the BarCodeBuilder class. The pre-defined border types in ITF14BorderType enumeration are as follows:

ITF14 Border Type

Value

Description

Bar

2

Two horizontal bars enclosing the barcode

BarOut

4

Two horizontal bars enclosing the barcode. It drawn outside of the barcode, and does not affect the height

Frame

1

Frame enclosing the barcode

FrameOut

3

Frame enclosing the barcode. It drawn outside of the barcode, and does not affect the height

None

0

No border enclosing the barcode

Border Type : BarOut

Two horizontal bars enclosing the barcode, It drawn outside of the barcode, and does not affect the height.

Border Type : FrameOut

Frame enclosing the barcode, It drawn outside of the barcode, and does not affect the height.

Specify Border Thickness for ITF14 Barcode

BarCodeBuilder class allows you to specify the Border Thickness of the barcode ITF14 Symbology. Let's experience this feature and know how it works. Developers can customize the border thickness of the ITF14 barcode image using ITF14BorderThickness property of the Aspose.BarCode class.

Get Minimum BarCode Size

BarCodeBuilder class allows you to get the minimum size that is required to generate a barcode. Let's experience this feature and know how it works. Developers can call the GetMinimumBarCodeSize method of the BarCodeBuilder class that will return an instance of SizeF. Following is the simple code demonstration.

Labels
  • No labels