Chapter 6. Working with Low Resolution Devices

The top priority when making barcode images is to make sure that the barcode is readable. Although it seems quite obvious, it is nevertheless not a trivial task, especially when working with a low-resolution device. A low-resolution device is a printer or any target device that has a resolution lower than 300 dpi. A typical example is G3 fax transmission, which has a resolution only at 200 dpi. The computer display has a resolution of 96 dpi. Many thermal transfer printers also fall into this category, with resolution as low as 203 dpi.

Table 6.1. Typical Low Resolution Devices

DeviceResolution
Computer display96 dpi
G3 Fax machine200 dpi
Thermal Transfer Printer203 dpi
Dot matrix printer150 dpi, 240 dpi, 300 dpi

Why does device resolution become an issue? Modern computer graphics technology is based on a fundamental assumption that the program can address any logical units, being 1/100 inch per unit, or 1/1000 inch per unit. In this way, computer graphics simplifies the drawing process and makes the drawing data more portable. In practice, most devices are raster and the smallest unit they can address is a pixel. You can not print on 1.5 pixels. Even worse, the size of pixel does not match the English or metric unit system used in our daily lives. Let's take a look at the pixel size measured in mils and mm:

Table 6.2. Pixel Size Under Typical Resolutions

dpi (dots per inch)size in milssize in mm
9610.420.265
1506.670.169
2034.930.125
2404.170.106
3003.330.085
6001.670.042

As you can see, the size of pixel is variable from device to device. For a 600-dpi laser printer, there are 600 pixels in an inch. The same number of pixels occupy 6.25 inches on a computer screen, much longer than the one on the printer. To eliminate the tedious work converting the units back and force, computer graphic layer allows drawing commands to be specified with lengths in a logical unit. You could use pixel based drawing, but naturally most of software choose a mapping unit in mils (1/1000th inch) or 0.01 millimeters. This makes programming a lot easier, because the software does not need to address on the pixel level and the drawings are portable from device to device. Unfortunately, this approach works under a major assumption - the actual resolution does not impact the quality of the drawing. This assumption holds true for text renderings and pictures, but not for barcode printing which requires great assurance on the constant width of each element. Converting from logical units to pixels usually results in rounding errors. When rounding errors are accumulated all the way, some elements will no longer keep the required constant widths, resulting in a low quality barcode.

6.1. Problem

To make high quality barcodes, several work-arounds have been adopted by barcoding software:

  • Requiring the use of high-resolution printers

  • Requiring use of Magic Numbers as NarrowBarWidth

  • Forcing the use of pixels as length units

The pixel size of a high resolution device is too small to be noticeable by even high resolution scanners. The overall accumulation of rounding errors is small. The barcode printed is also very accurate - meaning that you can always achieve the size you want on a high resolution printer.

Another way is to make the width value closest to integral times of a pixel length. Our testing found that this approach worked very well when the bar code element width occupying at least 2 pixels. Based on this theory, when you carefully select the element width value you can still achieve a grade A barcode on a low-resolution printer.

Some software only work with specific barcode printers. They work around the issue by allowing user to enter the length values in the number of pixels. The problem with this approach is that the barcode data is only meaningful to certain category of printers. The barcode data is not portable.

6.2. Magic Numbers

By making the logical units closest to the integral times of the width of a pixel, we calculate the magic numbers as shown in the table below:

Table 6.3. Magic Numbers

dpi (dots per inch)pixel size in milsmagic numbers (in mils)
9610.4221, 31
1506.6714, 20
2034.9310, 15
2404.178, 13, 17
3003.337, 10, 14
6001.677, 9, 10, 12

From the table above, the smallest width achievable on a 203-dpi thermal printer is 10 mils. On a low-resolution printer you can not achieve high precision - the achievable smallest width on a 203 dpi thermal printer is 5 mils and on the computer screen it is around 10 mils.

When you create barcodes under the screen resolution (96 dpi), you end up with a big X dimension value - 21 mils. As previously analyzed, 1X does not work very well because the accumulated rounding errors may result in a complete loss of an element.

6.3. Solution

To solve the barcode quality issue while retainig maximum portability, our Barcode ActiveX aligns all lengths to the edge of pixels. Moreover, the drawings are now in the unit of pixels, instead of any logical units. Doing this ensures you get a quality barcode even on low resolution devices when you are drawing a width at 1-pixel's width level.

However, this approach brings some side effects. Due to the priority to ensure the constant width, the overall length achieved may vary from device to device. You may find that the same barcode prints much bigger or smaller on a thermal printer than on a laser printer. You have to give up the precision to gain the quality. Secondly, the pixel level drawing only happens when ZoomRatio=1.

As you can see from the table, lengths of the barcodes are almost the same on high resolution printers ( 300 dpi and 600 dpi). But on low-resolution printers, it varies greatly, especially on the computer display.

During the rasterization process, the printer driver is consulted to get the best rendition. Text character usually appear bigger than their renditions on laser printers, and some printer models have problem rendering bold fonts. We recommend you do more testing when working on these low-resolution devices, and stick to one configuration which meets the quality and performance.

On low resolution devices, the choices for the actual NarrowBarWidth are limited, especially when we want the barcode as small as possible. The program calculates the NarrowBarWidth based on the resolution of the target device. Although you can specify different values, you may not get different results because the program only draws bars/spaces to the pixel edge. For example, when Barcode ActiveX draws on a computer display, specifying NarrowBarWidth as 8 mils renders the same barcode as with NarrowBarWidth set to 14 mils. Both lengths turn into 1 pixel at the time of rendering.

With the overall barcode length varying from device to device, the overall layout may look different too.

6.4. Transferring Images

Graphics exchange file formats are invented to allow the drawings to be transferred from one program to another. Fundamentally there are two categories: vector graphics format and raster graphics format. A vector graphics file stores drawing commands. On the target device, the drawing commands are replayed.

Many people think that the image files produced under high resolutions will have the best quality. This is not correct. When an image produced based on high resolution is renderred on a low resolution printer, the render program has to scale down all lengths. If it is a raster image, several adjacent pixels are compressed into one pixel. If it is a vector image, the lengths are divided by a ratio and rounded to the nearest integer. This transformation process likely causes rounding errors. When the bar width is small, the widths of elements become non-constant, and some drawings may be lost during the compression process.

Transferring images produced based on low resolution to a high resolution device may also have problems, but to a lesser degree. First, if two resolutions are compatible (for example 300 -> 600) there is no distortion or loss at all. And there are no rounding errors converting the logical units to the device units in the second device. Secondly, even if the two resolutions are not compatible (96 dpi -> 600 dpi), the pixel size in the second device is too small that one more or less pixel won't affect the barcode quality at all. And most of important, narrow elements won't be lost when scaled up.

As a result, you should pay special attention when you have to transfer images from one to another. Obviously, the best approach is to produce images under a resolution that matches the target printer. Barcode ActiveX automatically rounds all length values to the pixel level.

Needlessly to say, you may not have the control over the process under some circumstances. We list several common cases below:

  1. Exporting raster images

    Raster images (JPEG, GIF, TIF, PNG and BMP) can be exported through ExportImage method. During the export process, drawing commands are converted into an array of color information. The resolution used during the transform is specified in RasterImageResolution. You should set RasterImageResolution the same value as the resolution of your target printer.

  2. Exporting EMF images

    EMF is the recommended format for exporting. It produces a small size file. During the transform process, the default printer driver is consulted for the pixel size. As a result, you should set the target printer default when exporting EMF files. There are two methods to export EMF images. The first one is to call ExportImage method of the control. The second one is to get Picture property and retrieve the handle.

  3. Exporting WMF images

    WMF is a vector graphics format; however it does not contain frame size information. Barcode ActiveX uses 1440dpi as the reference resolution when rendering WMF images. Normally you won't encounter readablity issues when working on high resolution devices such as laser printers.

  4. Creating barcodes at web server side

    It is tough to create barcode images at web server and send to the client browser. The problem is that most web browsers only support raster image formats at screen resolution. You can use either screen resolution (96 dpi), or the resolution of target printer, however, in the latter case you will need to calcualte the screen size by youself. Consult Chapter 10, Using Barcode ActiveX in IIS for more information.

  5. Creating barcodes in Microsoft Office

    Microsoft Office programs either retrieve either WMF handles, or EMF handles at 1440 dpi. As a result you will need a high-resolution printer to render the image without loss.

It should be noted that some image processing programs have no concept of "resolution". Although they support vector graphics format, however they simply raster the image into pixels at screen resolution. As a result, if the original images were produced based on a higher resolution, the resulted barcodes usually have very low quality. Do not use those programs to edit barcode images exported from Barcode ActiveX.