FAQ TBarCode DLL / TBarCode Library
How Can I Save a Bitmap To Memory
How Can I Save a Bitmap To Memory
Below is a code sample how to use BCSaveImageToBuffer:
#include "windowsx.h"
// after BCCreate(..)
// generate image in buffer
LPBYTE lpBuffer;
eCode = BCSaveImageToBuffer (pBarCode, &lpBuffer, eIMBmp, nWidth, nHeight, 96.0, 96.0);
if (eCode == ErrOk)
{
// lock buffer before reading
if (GlobalLockPtr(lpBuffer))
{
// retrieve size of buffer
int nSize = GlobalSize((HGLOBAL)GlobalHandle(lpBuffer));
// process buffer
for (int i=0; i< nSize; i++)
{
BYTE byte = (static_cast<LPBYTE> (lpBuffer))[i];
// ...
}
// unlock after reading (required)
GlobalUnlockPtr(lpBuffer);
}
// free memory (required)
GlobalFreePtr(lpBuffer);
}
Alternative API Functions
ERRCODE BCBitmapToMemory (t_BarCode *pBarCode, VOID *pHandle, LPCSTR pszFormat,
INT *pnSize, LPCRECT pRect)
Writes barcode in an image format to memory block. Does not require global heap memory (=is faster) but does not render the HRT.
Even if you use an escape sequence for binary data the encoder will use code page conversion (example: \x88 leads to a different value in Data Matrix as desired).
Solution:
- Switch off code page conversion (use encoding mode LowByte)
- Force binary encoding mode if available (see PDF417 encoding mode, Data Matrix EnforceBinaryEncoding)
Relevant for DP Premium Address and other applications where you encode binary data in a 2D symbol (Data Matrix etc).