10.2. Creating Image based on Printer Resolution

You can create images with other resolutions, for example, the target printer's resolution. This approach gives you much better flexibility, and most sizing requirements derive from the printer resolution. However, this approach suffers a major disadvantage: you have to specify the size in terms of screen pixels. Without specifying the screen size, the browser maps one image pixel to one screen pixel, resulting in a much bigger image appearing on the screen.

So you have to calculate the screen pixels and set the size. At the print time, the pixels are scaled up to match the physical size. Each step may cause rounding errors. Fortunately, we found that as long as planned properly, we can still get pretty good results.

Note: the ExportImage method is device dependent because rounding errors may also happen when the drawing units are incompatible with the device units. To ensure best quality, you need to have the printer driver available at the server end. The printer does not need to be connected physically. The image created reflects the exact print effect when the value of RasterImageResolution property matches the printer resolution.

The barcode images created from the first approach can be “screen copied” while retaining its readability. This is not the case for barcodes created from the second approach. Try to scan the sample images (both are screen copies), the barcodes on the left have much better readability. On the other side, the second approach gives you more control on the NarrowBarWidth values.

The image created from the second approach is also much bigger than the ones targeting at the screen resolution. The bigger the image size is, the more time it takes to transmite over the network and load the image.

The table below lists the feature comparison of the two approaches:

  Pros Cons
Creating barcodes based on screen resolution No need to calculate the size of the image. Image can be screen copied while retaining high quality. Image size is usually very small; less time in downloading and loading the images. The NarrowBarWidth must align to the edge of the screen pixel, resulting in few choices
Creating barcodes based on target printer resolution More choices on the value of NarrowBarWidth. Need to calculate the image size in screen pixels. “Screen copied” barcode usually have very low quality. Image size is much bigger; More time needed to download and load the image.