Konica Minolta Darwin VDP Software User Manual
Page 86

Page 86 of 92
T EC - I T B a r c o d e So f t w a re R e f e re n c e
First we calculate the barcode width in device pixels:
Therefore we convert the width (which is given in mm) to inches. Then we multiply the result by the
resolution (dots per inch) of the output device.
60 / 25.4 * 200 472.44 dots (or pixels)
Then we calculate the module width and adopt it, so that all bars and spaces can be displayed with
whole pixels:
// 1) Specify the barcode type, the barcode data, etc.
//
// Do your barcode adjustments here!
// 2) Specify the favored barcode size.
// For optimizing the output quality we will do all calculations in device pixels.
// Therefore the given size (in this case in mm) must be converted to device pixels
// with respect to the resolution of the output device.
LONG ldpi = 200;
LONG lBarcodeWidth = (LONG)ConvertMMToPixel (60.0f, ldpi);
// 60 mm --> 472.44 pix
LONG lBarcodeHeight = (LONG)ConvertMMToPixel (30.0f, ldpi);
// 30 mm --> 236.22 pix
// 3) Get the horizontal module count.
// This function returns the number of modules that was calculated for the given
// barcode. This is usually an integer! For non-integer values the optimization
// will not work!
DOUBLE dCountModules = ::BCGetCountModules ( pBC );
DOUBLE dModuleWidth;
// avoid division by zero
if( dCountModules > 0.0)
{
// 4) Calculate the current module width:
// --> Divide the barcode width by the horizontal module count.
dModuleWidth = (DOUBLE)lBarcodeWidth/dCountModules;
// 5) Optimize the module width:
// For an optimal barcode the module width must be a multiple of one device pixel!
// Thus all decimal places have to be eliminated.
// In this case the value is rounded up with the ceil() function.
dModuleWidth = ceil ( dModuleWidth );
// 6) Now that you have found the optimal module width
// calculate the width of the complete barcode in target device pixels.
lBarcodeWidth = (LONG)(dCountModules * dModuleWidth);
}
// 7) The optimized barcode width can now be used to draw the barcode or to save
// the barcode as an image. In this sample the barcode will be saved as an image.
::BCSaveImage ( pBC, "C:\\ MyBarcode.BMP", eIMBmp,
lBarcodeWidth, lBarcodeHeight, ldpi, ldpi );
B.9.2
2D Barcodes
For 2D barcodes we have to do both a vertical and a horizontal size adjustment.
Barcode width = 60 mm
Barcode height = 30 mm (assuming a rectangular 2D barcode like PDF417)
Resolution of the output device = 200 dpi
The following code example shows the complete calculation which is necessary for optimizing a 2D
barcode for the given output device resolution:
// 1) Specify the barcode type, the barcode data, etc.
//
// Do your barcode adjustments here!
// 2) Specify the favored barcode size.
// For optimizing the output quality we will do all calculations in device pixels.
// Therefore the given size (in this case in mm) must be converted to device pixels