Produce High Quality Raster Images with Barcode ActiveX

The TAL Barcode ActiveX control has a SaveBarCode method that supports saving barcodes in the WMF, GIF, JPEG, PNG, EPS, TIFF, BMP, TGA, and PCX file formats. Most Web browsers support GIF and JPEG files and versions 4.0 and above of both Netscape and Internet Explorer fully support PNG files.

All of the browser supported file formats GIF, JPEG and PNG are raster style images meaning that they are made up of an array of pixel values. Raster images are not “device independent” meaning that it is possible to obtain different results on different output devices. The reason for this is that raster images contain a specific number of pixels across and a specific number of rows of pixels. To obtain the highest quality output, raster images should be created at the same “dot resolution” as the printer that they will be printed on.

The dot resolution of most printers is almost always much higher that the dot resolution for most display monitors therefore when you display a raster image on a display monitor, it will be much larger than the same image outputted to a printer. For example if you have a raster image that consists of 300 pixels across and 300 rows of pixels and you print that image on a printer that has a dot resolution of 300 dots per inch, you will end up with a one inch square image. If you render the same image on a display monitor that has a dot resolution of 100 dots per inch, you end up with an image that is three inches square. If you want the image to print at a high enough resolution to produce a high quality barcode (typically 300 DPI or greater) however you want the image to appear on the display monitor at the same size that will actually be printed on the printer, you must scale the image by the ratio of the screen resolution to the printer resolution. Most programs (including web browsers) that work with raster images provide features that allow you to scale images to any desired size on screen while retaining any higher resolution information when the image is sent to a printer. For example, when you place an image tag in an HTML document, you can also supply Height and Width tags that instruct the browser to scale the image to the desired size on screen no matter what the original image resolution is.

Scaling a raster image involves either adding or removing pixels to force the image to a particular size. This process can causes the image quality to degrade significantly when it is outputted to the screen. Likewise, if you were to create the image at the screen resolution so that it appears at the correct size on screen without having to scale it and then scale the image up before sending it to a printer (so that it prints at the same size as the image on screen), you will end with a printed output that is too low resolution and too low quality to result in a readable barcode.

When creating barcodes, you are always better off creating the image at the resolution of the target printer and then scaling it down on screen to the desired size. This way, the image should at least print at a high resolution even though it may appear low in quality on screen. The important point is that you want your barcodes to be readable from a printed page. Most barcode readers are not capable of reading barcodes from a computer screen therefore barcodes are only useful when read from a printed page.

When you do not know the resolution of the target printer (or the resolution of the display device), i.e., when generating barcode images that will be displayed in a web page, the best that you can do is make educated assumptions. You can assume that most of your target users will have a 300 DPI or greater printer and therefore create your barcode images using 300 pixels per inch for the RasterImageResolution property of the TAL Barcode ActiveX Control.

Because you do not know with certainty the resolution of the display used to view your web pages, you do not know in advance how the image should be scaled in the browser window. You can set the Height and Width of an image in HTML code so that the browser will scale the image to a desired size in pixels, however without knowing the screen resolution you do not know how big a screen pixel is. The TAL Barcode ActiveX control provides a Height and Width property so that you can determine the true size of your barcodes however when working with raster images, the actual height and width that you end up with is dependent on the dot resolution of both the image and the output device. Fortunately the Windows operating system always assumes that the screen resolution is 96 pixels per inch no matter what the true value is so scaling images under Windows is trivially easy. My guess is that Mac and UNIX systems also use the same value of 96 pixels per inch for all display devices however this has not been confirmed.

It is extremely important you scale the width of a barcode as close as possible to the actual width that is returned by the control after a barcode is generated. The width of most barcodes will vary depending on the amount of data that you encode. If you scale the width of a raster image of a barcode to a value that is not the same (or as close as possible) to the actual width returned by the control, the browser will scale the image by either adding or removing columns of pixels which will distort the widths of the bars and spaces in the barcode and in the worst case, remove entire bars or spaces (or stretch some of the bars or spaces) and thus cause the barcode to become unreadable.

When attempting to produce barcodes as raster style images, we strongly recommend that you test the printed output thoroughly to make sure that your barcodes will be readable. Unfortunately we can make no guarantees on the readability of any barcodes rendered as raster images. You should be able to obtain good results under most circumstances if you understand how raster images work and develop your application to work within their limitations.

Contact Us