L_BarCodeWriteExt2

#include "ltbar.h"

L_INT EXT_FUNCTION L_BarCodeWriteExt2(pBitmap, pBarCodeData, pBarCodeColor, ulFlags, pBarCode1D, pBarCodePDF, pBarCodeDM, pBarCodeQR, lprcSize)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

PBARCODEDATA pBarCodeData;

/* pointer to the BARCODEDATA structure */

pBARCODECOLOR pBarCodeColor;

/* pointer to the BARCODECOLOR structure */

L_UINT32 ulFlags;

/* flags that indicate the function behavior */

pBARCODE1D pBarCode1D;

/* pointer to the BARCODE1D structure */

pBARCODEWRITEPDF pBarCodePDF;

/* pointer to the BARCODEWRITEPDF structure */

BARCODEWRITEDM pBarCodeDM;

/* pointer to the BARCODEWRITEDM structure */

pBARCODEWRITEQR pBarCodeQR;

/* pointer to the BARCODEWRITEQR structure */

LPRECT lprcSize;

/* pointer to the RECT structure to be updated */

Writes linear, PDF, Data Matrix, and QR barcode symbols over the bitmap.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the bitmap on which the barcode will be written.

pBarCodeData

Pointer to a BARCODEDATA structure that contains the barcode information to be written over the image.

pBarCodeColor

Pointer to the BARCODECOLOR structure that contains the color information to be written over the image. Pass NULL to write barcode using the default colors.

ulFlags

Flags that indicate the function behavior. You can combine values when appropriate, by using a bitwise OR ( | ). The following values are used only when you want to write Data Matrix or PDF barcodes. Pass 0 to use the default values, based on the type of barcode being written.  Possible values are:

 

Value

Meaning

 

BARCODE_TRUNCATE

[0x0010] Write Truncated PDF4167 symbols.

 

BARCODE_MSGAPPEND

[0x0020] Write the barcode symbol in the group mode. Used for PDF.

 

BARCODE_INITREADER

[0x0040] Write the reader initialization flags for Data Matrix and PDF barcodes.

 

BARCODE_DISABLE_COMPRESSOPN

[0x0100] Write Data Matrix symbols without compression.

 

BARCODE_COLROWASLIMITS

[0x0080] Use column and row values as limits when a PDF symbol is written.

 

BARCODE_USECOLORS

[0x0200] Write color barcode. The colors are used as the exact bar and space colors for searching for the barcode.

 

BARCODE_TRANSPARENT

[0x0400] Write barcodes with a transparent background. This is not recommended.

 

BARCODE_JUSTIFYRIGHT

[0x0010] Justify linear barcode symbols to the right side of the window described by BARCODEDATA.rcBarLocation.

 

BARCODE_JUSTIFYHCENTER

[0x0020] Justify linear barcode symbols to the horizontal center of the window described by BARCODEDATA.rcBarLocation.

pBarCode1D

Pointer to the BARCODE1D structure that contains the information related to linear barcodes. Pass NULL to use the default or if you don't want to write a linear barcode.

pBarCodePDF

Pointer to the BARCODEWRITEPDF structure that contains the information related to PDF417 barcodes. Pass NULL to use the default or if you don't want to write a PDF417 barcode.

pBarCodeDM

Pointer to the BARCODEWRITEDM structure that contains the information related to Data Matrix barcodes. Pass NULL to use the default or if you don't want to write a Data Matrix barcode.

pBarCodeQR

Pointer to the BARCODEWRITEQR structure that contains the information related to QR barcodes. Pass NULL to use the default or if you don't want to write a Data QR barcode.

lprcSize

Pointer to the RECT structure to be updated with the barcode size before writing the barcode over the bitmap. If the user passes a valid pointer, then the function will calculate the size of the barcode and will update this parameter with the barcode size. Pass NULL to write the barcode.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

While the L_BarCodeWriteExt function writes linear, PDF and Data Matrix barcodes only, the L_BarCodeWriteExt2 function writes all these barcodes, as well as QR barcodes.

This function supports all bitmaps currently supported by LEADTOOLS.

You must pass an allocated bitmap to this function.  If you did not pass an allocated bitmap, the function wil return an error code.

The L_BarCodeWriteExt2 function will write the barcode symbol over the bitmap using the rectangle defined by the rcBarLocation member in the BARCODEDATA structure. However, if the bitmap has a region, this function will write the barcode using the region boundaries.

If the region is non-rectangular, the barcode will be written to the rectangle bounding the region and subsequently clipped to the given region. This might cause the resulting barcode to be unreadable.

If you set the ulFlags parameter to BARCODE_USECOLORS, then this function will use the pBarCodeColor parameter, otherwise the function will ignore it and use the default colors of black for bars and white for spaces.

Using colors does not apply for 1 bit per pixel images.

The BARCODE_USECOLORS and BARCODE_TRANSPARENT are used with all barcode types.

Required DLLs and Libraries

LTBAR

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

L_BarCodeRead, L_BarCodeFree, L_BarCodeIsDuplicated, L_BarCodeGetDuplicated, L_BarCodeGetNextDuplicated, L_BarCodeVersionInfo, L_BarCodeGetFirstDuplicated, L_BarCodeWriteExt

Topics:

Programming with LEADTOOLS Barcode

BarCode API Function Groups

Example

For complete sample code refer to MFCBar32 demo.

L_INT TestBarCodeWrite2 (HWND hWnd, pBITMAPHANDLE pBitmap)
{
   L_TCHAR      szBuffer[256];
   BARCODEDATA BarCodeData;
   BARCODECOLOR BarColor;
   BARCODE1D   Bar1D;
   L_INT       nRet;

   memset(&szBuffer, 0, sizeof(szBuffer));
   memset(&BarCodeData, 0, sizeof(BARCODEDATA));
   memset(&Bar1D, 0, sizeof(BARCODE1D));
   BarColor.dwColorBar = RGB(0, 0, 255);
   BarColor.dwColorSpace = RGB(255, 0, 0);

   BarCodeData.rcBarLocation.left = 50; // 1/2 inch
   BarCodeData.rcBarLocation.top = 50; // 1/2 inch
   BarCodeData.rcBarLocation.right = 150; // 1.5 inch (width = 1 inch)
   BarCodeData.rcBarLocation.bottom = 100; // 1 inch (height = ½ inch)
   BarCodeData.nUnits = BARCODE_SCANLINES_PER_PIXELS;
   BarCodeData.ulType = BARCODE_1D_EAN_13;
   BarCodeData.pszBarCodeData = "123456789012";  
   BarCodeData.nSizeofBarCodeData = strlen(BarCodeData.pszBarCodeData);

   Bar1D.bErrorCheck = TRUE;
   Bar1D.bOutShowText= TRUE;

   nRet = L_BarCodeWriteExt2(pBitmap, &BarCodeData, &BarColor, BARCODE_USECOLORS,  &Bar1D, NULL, NULL, NULL, NULL);
   if (nRet == SUCCESS)
   {
      wsprintf(szBuffer, TEXT("A Barcode is written ..."));
      MessageBox(hWnd, szBuffer, TEXT("Notice!"), MB_OK);
   }
   else
   {    
      wsprintf(szBuffer, TEXT("An error occurred in L_BarCodeWriteExt2.\nError No. = %d\n"), nRet);
      MessageBox(hWnd, szBuffer, TEXT("Error!"), MB_OK);
   }

   return nRet;
}