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


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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值