FAQ TBarCode OCX
How Can I Create an Optimal Bitmap for 203 DPI in VB6?
How Can I Create an Optimal Bitmap for 203 DPI in VB6?
The sample code below uses a pre-set (custom) module width, sets the DPI and then calculates the total width of the symbol. The principle works for other printers, too.
The OCX method BCWidthHdc2 can be used to calculate the width of the barcode. If a module width has been set, use a dummy value for the [in] nWidth. If you calculate the width in unit=mm, convert it to Pixels for the SaveImage function. If you create a 2D code, use the BCHeightHd2 function for the height.
Sample Code:Dim widthPx As Long Dim heightPx As Long Dim heightMM As Double TBarCode111.Dpi = 203 TBarCode111.SizeMode = eSizeMode_CustomModuleWidth ' =1 TBarCode111.ModuleWidth = "250" heightPx = 100 heightMM = heightPx * (25.4 / TBarCode111.Dpi) widthPx = TBarCode111.BCWidthHdc2(0, 1000, heightMM * 1000, eMUPixel) TBarCode111.SaveImage "c:\temp\test.bmp", eIMBmp, widthPx, heightPx, 203, 203
A module width of 0.250 mm corresponds to 2 printer pixels at 203 dpi resulting in an optimal quality. Always use an integer multiple of 1 Pixel (0.12512 mm)