Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Visual C++ Example for PDF417 Encoder SDK/DLL

Visual C++ Example for PDF417 Encoder SDK/DLL 4 years 4 months ago #3893

void CPDF417Vc6TestDlg::OnEncode()
{
PDF417CONTEXT tPDF417Ctx;

InitWorkSpace(&tPDF417Ctx);

tPDF417Ctx.nErrorCorrectLevel = m_Level.GetCurSel()+1;

tPDF417Ctx.nColumns = m_nColumns;
tPDF417Ctx.nRows = m_nRows;
tPDF417Ctx.nMargin = m_nMargin;
tPDF417Ctx.clBackGround = m_BackColor.GetColor();
tPDF417Ctx.clForeGround = m_ForeColor.GetColor();
if (m_strText != "") memcpy(tPDF417Ctx.cData,m_strText.GetBuffer(0),m_strText.GetLength());
tPDF417Ctx.nSize = m_strText.GetLength();
FreeWorkSpace();
hbmp =PDF417Encode2Bitmap(&tPDF417Ctx);

Invalidate();
}

BOOL CPDF417Vc6TestDlg::SaveBitmapToFile(HBITMAP hBitmap , LPCTSTR lpFileName)
{

HDC hDC;


int iBits;


WORD wBitCount;

DWORD dwPaletteSize=0,
dwBmBitsSize,
dwDIBSize, dwWritten;


BITMAP Bitmap;


BITMAPFILEHEADER bmfHdr;


BITMAPINFOHEADER bi;


LPBITMAPINFOHEADER lpbi;


HANDLE fh, hDib;
HPALETTE hPal,hOldPal=NULL;


hDC = CreateDC("DISPLAY",NULL,NULL,NULL);
iBits = GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES);
DeleteDC(hDC);

if (iBits <= 1)
wBitCount = 1;
else if (iBits <= 4)
wBitCount = 4;
else if (iBits <=
wBitCount = 8;
else if (iBits <= 24)
wBitCount = 24;
else
wBitCount = 32;

if (wBitCount <=
dwPaletteSize = (1 << wBitCount) *sizeof(RGBQUAD);


GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = Bitmap.bmWidth;
bi.biHeight = Bitmap.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = wBitCount;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;

dwBmBitsSize = ((Bitmap.bmWidth *wBitCount+31)/32)* 4*Bitmap.bmHeight ;


hDib = GlobalAlloc(GHND,dwBmBitsSize+dwPaletteSize+sizeof(BITMAPINFOHEADER));
lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib);
*lpbi = bi;


hPal = (HPALETTE)GetStockObject(DEFAULT_PALETTE);
if (hPal)
{
hDC = ::GetDC(NULL);
hOldPal = SelectPalette(hDC, hPal, FALSE);
RealizePalette(hDC);
}

GetDIBits(hDC, hBitmap, 0, (UINT)Bitmap.bmHeight,(LPSTR)lpbi + sizeof(BITMAPINFOHEADER)+dwPaletteSize,(LPBITMAPINFO)lpbi, DIB_RGB_COLORS);


if (hOldPal)
{
SelectPalette(hDC, hOldPal, TRUE);
RealizePalette(hDC);
::ReleaseDC(NULL, hDC);
}


fh = CreateFile(lpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);

if (fh == INVALID_HANDLE_VALUE)
return FALSE;

bmfHdr.bfType = 0x4D42; // "BM"
dwDIBSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwPaletteSize + dwBmBitsSize;
bmfHdr.bfSize = dwDIBSize;
bmfHdr.bfReserved1 = 0;
bmfHdr.bfReserved2 = 0;
bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER)+ dwPaletteSize;

WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL);

WriteFile(fh, (LPSTR)lpbi, dwDIBSize, &dwWritten, NULL);


GlobalUnlock(hDib);
GlobalFree(hDib);
CloseHandle(fh);

return TRUE;
}
The administrator has disabled public write access.

  • Posts:59
  • developer's Avatar
  • developer
  • Moderator
  • OFFLINE
  • Karma: 1
  • Page:
  • 1
Time to create page: 0.167 seconds
Powered by Kunena Forum :: Wibi