#include "ltbar.h"
L_LTBAR_API L_INT L_BarCodeWrite(pBitmap, pBarCodeData, pBarCodeColor, ulFlags, pBarCode1D, pBarCodePDF, pBarCodeDM, pBarCodeQR, pBarCodeAZTEC, pBarCodeMAXI, pBarCodeMICROQR, lprcSize)
Writes linear, PDF417, MicroPDF417, Data Matrix, QR, Aztec, Maxi and MicroQR barcodes over the bitmap.
Pointer to the bitmap handle referencing the bitmap on which the barcode will be written.
Pointer to a BARCODEDATA structure that contains the barcode information to be written over the image.
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.
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 PDF417 symbols. |
BARCODE_MSGAPPEND | [0x0020] Write the barcode symbol in the group mode. Used for PDF and MicroPDF. |
BARCODE_INITREADER | [0x0040] This flag is for backward compatibility and is no longer used. |
BARCODE_DISABLE_COMPRESSOPN | [0x0100] Write Data Matrix symbols without compression. |
BARCODE_COLROWASLIMITS | [0x0080] Use the column and row values as limits when a PDF or MicroPDF symbol is written. |
BARCODE_USECOLORS | [0x0200] Write color barcodes. 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. |
BARCODE_MICRO_PDF417_MODE128 | [0x1000] If set, use the Function Code word for Code 128 emulation. Only used for MicroPDF417. |
BARCODE_MICRO_PDF417_LINKED | [0x2000] If set, the MicroPDF417 barcode is linked to a linear symbol that is printed below it. Only used for MicroPDF417. |
BARCODE_1D_USE_XMOD | [0x0100]If set, the barcode writer will use nXModule in pBarCode1D as the width of the smallest bar for 1D barcodes. Otherwise, it will calculate the width of the smallest bar in order to fill the specified area. |
Pointer to the BARCODE1D structure that contains the information related to linear barcodes. Pass NULL to use the default or if you do not want to write a linear barcode.
Pointer to the BARCODEWRITEPDF structure that contains the information related to PDF417 and MicroPDF417 barcodes. Pass NULL to use the default or if you do not want to write a PDF417 barcode.
Pointer to the BARCODEWRITEDM structure that contains the information related to Data Matrix barcodes. Pass NULL to use the default or if you do not want to write a Data Matrix barcode.
Pointer to the BARCODEWRITEQR structure that contains the information related to QR barcodes. Pass NULL to use the default or if you do not want to write a Data QR barcode.
Pointer to the BARCODEWRITEAZTEC structure that contains the information related to AZTEC barcodes. Pass NULL to use the default or if you do not want to write an Aztec barcode.
Pointer to the BARCODEWRITEMAXI structure that contains the information related to MAXI barcodes. Pass NULL to use the default or if you do not want to write a MAXI barcode.
Pointer to the BARCODEWRITEMICROQR structure that contains the information related to MICROQR barcodes. Pass NULL to use the default or if you do not want to write a MICROQR barcode.
Pointer to the RECT structure to be updated with the barcode size before writing the barcode over the bitmap. If a valid pointer is passed, the function will calculate the size of the barcode and will update this parameter with the barcode's size. Pass NULL to write the barcode.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
The L_BarCodeWrite function writes linear, PDF417, MicroPDF417, Data Matrix, QR, Aztec, Maxi and MicroQR barcodes.
QR stores up to 2335 ASCII characters in one barcode symbol.
DataMatrix stores up to 2218 ASCII characters in one barcode symbol.
PDF417 stores up to 1,850 ASCII characters in one barcode symbol.
MicroPDF stores up to 366 ASCII characters in one barcode symbol.
This function supports all bitmaps currently supported by LEADTOOLS.
You must pass an allocated bitmap to this function. If you do not pass an allocated bitmap, the function wil return an error code.
The L_BarCodeWrite 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.
For a table containing information useful when writing 1D barcode data, refer to Writing Linear 1D Barcodes.
For a table containing information useful when writing PDF barcode data, refer to PDF417 Barcodes in LEADTOOLS.
For a table containing information useful when writing QR barcode data, refer to QR Code Barcodes in LEADTOOLS.
Win32, x64, Linux.
For complete sample code refer to MFCBar32 demo.
L_INT BarCodeWriteExample(HWND hWnd, pBITMAPHANDLE pBitmap)
{
L_TCHAR szBuffer[256];
BARCODEDATA BarCodeData;
BARCODECOLOR BarColor;
BARCODE1D Bar1D;
L_INT nRet;
ZeroMemory(&szBuffer, sizeof(szBuffer));
ZeroMemory(&BarCodeData, sizeof(BARCODEDATA));
ZeroMemory(&Bar1D, sizeof(BARCODE1D));
BarColor.uStructSize = sizeof(BARCODECOLOR);
BarColor.dwColorBar = RGB(0, 0, 255);
BarColor.dwColorSpace = RGB(255, 0, 0);
BarCodeData.uStructSize = sizeof(BarCodeData);
BarCodeData.rcBarLocation.left = 50;
BarCodeData.rcBarLocation.top = 50;
BarCodeData.rcBarLocation.right = 250;
BarCodeData.rcBarLocation.bottom = 100;
BarCodeData.nUnits = BARCODE_SCANLINES_PER_PIXELS;
BarCodeData.ulType = BARCODE_1D_EAN_13;
BarCodeData.pszBarCodeData = "123456789012";
BarCodeData.nSizeofBarCodeData = (L_INT) strlen(BarCodeData.pszBarCodeData);
Bar1D.uStructSize = sizeof(BARCODE1D);
Bar1D.bErrorCheck = TRUE;
Bar1D.bOutShowText= TRUE;
nRet = L_BarCodeWrite(pBitmap, &BarCodeData, &BarColor, BARCODE_USECOLORS, &Bar1D, NULL, NULL, NULL, 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_BarCodeWrite,\nError No. = %d\n"), nRet);
MessageBox(hWnd, szBuffer, TEXT("Error!"), MB_OK);
return nRet;
}
return SUCCESS;
}