Konica Minolta Darwin VDP Software User Manual

Page 87

Advertising
background image



Page 87 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

// 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 and vertical 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!

LONG lCols = ::BCGet2D_XCols ( pBC );
LONG lRows = ::BCGet2D_XRows ( pBC );


// avoid division by zero

if( lCols > 0 && lRows > 0 )
{

// 4) Optimize the barcode width and height:
// 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.
// Then the module width/height is again multiplied by the module count.

lWidth = (LONG)ceil((DOUBLE)lBarcodeWidth /(DOUBLE)lCols) * lCols;
lHeight = (LONG)ceil((DOUBLE)lBarcodeHeight/(DOUBLE)lRows) * lRows;
}

// 5) The optimized barcode width and height 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.3

Prepare a Barcode with a specific Module Width for a Web Page

In the following example we want to create a barcode image with a module width of 15 mils. The
printer resolution is assumed to be 600 dpi.

So the module width is 0.015 * 600 = 9 device pixels.

Furthermore we want to generate a rather small image. Therefore we will use just 3 (instead of 9)
pixels as module width. This means the barcode image is actually optimized for a resolution of 200
dpi. For printing with 600 dpi the image will be scaled by 3 (3 * 3 = 9 device pixels).

That‟s perfect.

In order to prepare the image, we have to do the following steps:

Step 1: Create the Image

First we calculate the horizontal size of the barcode image in pixels. Therefore we multiply the
number of barcode modules width the intended module width (in pixel):

CntModules = tbc.CountModules

' the number of modules in the barcode

BitmapWidth = 3 * CntModules

' one module will be 3 pixels in the generated image

BitmapHeight = 100

' the height of the barcode image is half an inch

ImgByteArray = ConvertToStream (eIMBmp, BitmapWidth, BitmapHeight, ...)

Step 2: Scale the Image

Now we calculate the desired display size in the browser, so that the barcode will finally be printed
in the correct size on the printout. HTML assumes a screen resolution of 96 dpi. The image was
optimized for 200 dpi. Thus we have to scale the image for display in the browser by 96 / 200.

DispWidth = BitmapWidth * 96 / 200
DispHeight = BitmapHeight * 96 / 200

<img src="<%="Barcode.asp?" & URLPARAM%>"

width="<%=DispWidth%>"

height="<%=DispHeight%>”

This procedure works for web applications (

ConvertToStream

method) as well as for storing image

files (

SaveImage

method).

Advertising