读取点阵汉字库

终于可以在已经放进内存的resource里面读取hzk16的点阵了……折腾人啊!转换函数如下:

不爽ing……

// Function:void CharToPixel(CString *m_Str,int nLength)
// Todo: Convert a CString to 16*16 font in CByteArray byDisplay.
// Input: CString* m_Str, the pointer to the string to be converted.
// Input: int nLength, the length of the string.
// Return: None. Global variable CByteArray byDisplay contains the fonts.

void CLedctrlDlg::CharToPixel(CString *m_Str, int nLength)
{
	HRSRC hRes;
	HGLOBAL hglbData;
	HMODULE hm;
	unsigned char nSection, nPosition;
	long lHzkPosition;
	BYTE *lHzBase,*lp;
	int nChar,nByte;

	nLength=nLength/2;
	hm=AfxGetResourceHandle();
	hRes=::FindResource(hm, MAKEINTRESOURCE(IDR_HZK16), "HZK16");
	hglbData=::LoadResource(hm, hRes);
	lHzBase=(BYTE *)LockResource(hglbData);
	byDisplay.RemoveAll();
	byDisplay.SetSize(nLength*32);
	m_Str->OemToAnsi();
	for (nChar=0; nChar<nLength; nChar++)
	{
		nSection=m_Str->GetAt(nChar*2)-0xa0;
		nPosition=m_Str->GetAt(nChar*2+1)-0xa0;
		lHzkPosition=((nSection-1)*94+nPosition-1)*32;
		lp=lHzBase+lHzkPosition;
		for (nByte=nChar*32; nByte<(nChar+1)*32; nByte++)
		{
			byDisplay.SetAt(nByte,*(lp++));
		}
	}
	FreeResource(hglbData);
}

以上。
不弹此调久矣的老狼

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注