您的位置:首页 > 编程语言

QRCode二维条码开发(代码)_2011.05.24

2011-05-24 11:09 190 查看
11:09:36

//函数功能:字母数字模式下将输入的数据转换成信息码
//参数说明:
//strInput -- 原始输入数据
//strVersionNum -- 当前版本号
//strErrLevel -- 当前纠错等级
//返回值:strDataCode -- 返回编码后的码字
CString CQRCodeDlg::AlphaNumericMode(CString strInput, CString strVersionNum, CString strErrLevel)
{
AfxMessageBox("进入到字母数字模式编码函数!");
CString strDataCode;//输入数据按规则转换后的码字,也是此函数的返回值
CString strText = "123456FDedfdg";
CString strTemp;
strText = strInput;
int nLength = 0;//输入字符串的长度
int nValue = 0;
int nVersionNum = 2;//版本号
int nBits;//字符计数指示符的位数
char buffer[20];//存放11位二进制的缓冲区
char chEncodeMode = '2';//代表字母数字编码模式
strText.MakeUpper();
char cInput[2];
strVersionNum.Format("%d",nVersionNum);
nLength = strText.GetLength();
for(int i=0;i<nLength;i++)
{
if(i%2 != 0)
{
if(strText[i] >= '0' && strText[i] <= '9')
cInput[1] = strText[i] - 48;
else if (strText[i] >= 'A' && strText[i] <= 'Z')
cInput[1] = strText[i] - 55;
else if (strText[i] == 32)/*space空格*/
cInput[1] = 36;
else if (strText[i] == 36)/*$符号*/
cInput[1] = 37;
else if (strText[i] == 37)/*%符号*/
cInput[1] = 38;
else if (strText[i] == 42)/*星号*/
cInput[1] = 39;
else if (strText[i] == 43)/*加号*/
cInput[1] = 40;
else if (strText[i] == 45)/*减号*/
cInput[1] = 41;
else if (strText[i] == 46)/*点.*/
cInput[1] = 42;
else if (strText[i] == 47)/*斜杠*/
cInput[1] = 43;
else if (strText[i] == 58)/*冒号*/
cInput[1] = 44;
nValue = cInput[0]*45 + cInput[1];
_itoa(nValue,buffer,2);
strTemp.Format("%011s",buffer);
strDataCode += strTemp;
}
else if(i%2 == 0)
{
if(strText[i] >= '0' && strText[i] <= '9')
cInput[0] = strText[i] - 48;
else if (strText[i] >= 'A' && strText[i] <= 'Z')
cInput[0] = strText[i] - 55;
else if (strText[i] == 32)/*space空格*/
cInput[0] = 36;
else if (strText[i] == 36)/*$符号*/
cInput[0] = 37;
else if (strText[i] == 37)/*%符号*/
cInput[0] = 38;
else if (strText[i] == 42)/*星号*/
cInput[0] = 39;
else if (strText[i] == 43)/*加号*/
cInput[0] = 40;
else if (strText[i] == 45)/*减号*/
cInput[0] = 41;
else if (strText[i] == 46)/*点.*/
cInput[0] = 42;
else if (strText[i] == 47)/*斜杠*/
cInput[0] = 43;
else if (strText[i] == 58)/*冒号*/
cInput[0] = 44;
}
}
if(nLength%2 !=0)
{
nValue = cInput[0];
_itoa(nValue,buffer,2);
strTemp.Format("%06s",buffer);
strDataCode += strTemp;
}
_itoa(nLength,buffer,2);
nBits = IndicatorBits(chEncodeMode,nVersionNum);
switch(nBits)
{
case 9:
strTemp.Format("%09s",buffer);
break;
case 11:
strTemp.Format("%011s",buffer);
break;
case 13:
strTemp.Format("%013s",buffer);
break;
}
strDataCode = "0010" + strTemp + strDataCode;//模式指示符+字符计数指示符+数据
return strDataCode;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: