翻譯|使用教程|編輯:黃竹雯|2018-10-29 16:25:14.000|閱讀 480 次
概述:本系列教程會解答您在使用條形碼生成控件TBarCode SDK產品時遇到的絕大部分疑惑。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TBarCode SDK是一款可以在任意應用程序和打印機下生成和打印所有條碼的條碼軟件組件。TBarCode SDK對于Microsoft® Office 用戶以及軟件開發者提供條碼打印。使用此款條碼軟件組件您可以以完美效果生成和打印所有用于工業和商業條碼符號。
通常,我們建議API調用的此過程:
我們建議盡可能使用自定義模塊寬度 - 調整窄條寬度可以更好地控制輸出。它還允許您遵守特定的標簽要求和打印機的輸出分辨率。可能有一個例外:對于郵政條碼,條形碼大小必須在精確范圍內,邊界矩形可能就足夠了。
模塊寬度的示例值(符合300 dpi):
對于位圖輸出,模塊寬度可以適應于位圖分辨率(例如,96dpi)。在這里,您可以使用GetOptimalBitmapSize API調用。
下面是如何使用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);
}
調整適當的DC
使用以下屏幕DC創建具有消除鋸齒選項的字體渲染(根據屏幕調整):
HDC dc = CreateDC(TEXT(“DISPLAY”),NULL,NULL,NULL);
eCode = BCSaveImageEx(m_pbarCode,dc,file,imageType,100,widthPx,heightPx,dpi,dpi);
if(dc)
DeleteDC(dc);
調整正確的字體(LOGFONT)
使用Windows標準字體對話框或以下函數從Windows GDI檢索預初始化的LOGFONT結構:
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);
未完待續......
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn