翻譯|使用教程|編輯:黃竹雯|2018-10-29 16:25:14.000|閱讀 464 次
概述:本系列教程會(huì)解答您在使用條形碼生成控件TBarCode SDK產(chǎn)品時(shí)遇到的絕大部分疑惑。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
TBarCode SDK是一款可以在任意應(yīng)用程序和打印機(jī)下生成和打印所有條碼的條碼軟件組件。TBarCode SDK對(duì)于Microsoft® Office 用戶以及軟件開發(fā)者提供條碼打印。使用此款條碼軟件組件您可以以完美效果生成和打印所有用于工業(yè)和商業(yè)條碼符號(hào)。
通常,我們建議API調(diào)用的此過程:
我們建議盡可能使用自定義模塊寬度 - 調(diào)整窄條寬度可以更好地控制輸出。它還允許您遵守特定的標(biāo)簽要求和打印機(jī)的輸出分辨率。可能有一個(gè)例外:對(duì)于郵政條碼,條形碼大小必須在精確范圍內(nèi),邊界矩形可能就足夠了。
模塊寬度的示例值(符合300 dpi):
對(duì)于位圖輸出,模塊寬度可以適應(yīng)于位圖分辨率(例如,96dpi)。在這里,您可以使用GetOptimalBitmapSize API調(diào)用。
下面是如何使用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); }
TBarCode V6
'callback function Public Function MyDrawRow ( ByRef pMyData As Long, ByVal pBarCode As UIntPtr, ByVal hDC As IntPtr, ByVal hTargetDC As IntPtr, ByRef pRect As Rectangle) As UInt32 Dim strTempo As String strTempo = TBC6.BCGetMetaData(pBarCode) Return Convert.ToUInt32(0) End Function 'setting the address of the callback function Public cb As TBC6.Callback cb = AddressOf MyDrawRow eCode = TBC6.BCSetFuncDrawRow(hBarcode, cb, pData) 'required declarations Declare Ansi Function BCDrawCB Lib "TBarCode6.ocx" ( _ ByRef hBarcode As UIntPtr, _ ByVal hDC As IntPtr, _ ByRef pRect As Rectangle, _ ByVal func As Callback, _ ByVal func As Callback, _ ByVal pData As IntPtr ) As Int32 Declare Ansi Function BCGetMetaData Lib "TBarCode6.ocx" ( _ ByVal hBarcode As UIntPtr ) As String
DrawBarcode (HDC hDC, long xpos, long ypos) { RECT hRect; long lHRHeight = 0; ypos += GetFullHeight(); hRect.left = xpos; hRect.top = ypos; hRect.right = hRect.left + width; hRect.bottom = hRect.top + height; HDC memDC; HBITMAP memBMP, oldBMP; int width, height; RECT draw; width = abs(hRect.right - hRect.left); height = abs (hRect.bottom - hRect.top); draw.left = 0; draw.bottom = height; draw.top = 0; draw.right = width; memDC = CreateCompatibleDC(hDC); memBMP = CreateCompatibleBitmap(hDC, width, height); oldBMP = (HBITMAP) SelectObject(memDC, memBMP); if (S_OK = BCDraw(pBarcode, memDC, &draw)) { // scale / copy to target DC BitBlt(hDC, hRect.left, hRect.top, width, height, memDC, 0, 0, SRCCOPY); SelectObject(memDC, oldBMP); } DeleteObject(memBMP); DeleteDC(memDC); }
調(diào)整適當(dāng)?shù)腄C
使用以下屏幕DC創(chuàng)建具有消除鋸齒選項(xiàng)的字體渲染(根據(jù)屏幕調(diào)整):
HDC dc = CreateDC(TEXT(“DISPLAY”),NULL,NULL,NULL); eCode = BCSaveImageEx(m_pbarCode,dc,file,imageType,100,widthPx,heightPx,dpi,dpi); if(dc) DeleteDC(dc);
調(diào)整正確的字體(LOGFONT)
使用Windows標(biāo)準(zhǔn)字體對(duì)話框或以下函數(shù)從Windows GDI檢索預(yù)初始化的LOGFONT結(jié)構(gòu):
HFONT hSystemVariableFont = (HFONT ) GetStockObject( ANSI_VAR_FONT ); LOGFONT lfSystemVariableFont; GetObject ( hSystemVariableFont, sizeof(LOGFONT), &lfSystemVariableFont ); // Make sure that the following flags are set in the LOGFONT structure passed to BCSetLogFont(): lfOutPrecision (e.g. set to 3) lfClipPrecision (e.g. set to 2) lfQuality (e.g. set to 1) lfWeight (e.g. set to 400) lfFaceName should be set to a True Type font (e.g. “Arial”) // Calculate the font height as follows: lfHeight = = -MulDiv( 10 /*PointSize*/, GetDeviceCaps(hDC, LOGPIXELSY), 72);
未完待續(xù)......
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn