ASP.NET实现二维码(QRCode)的创建和读取实例(6)

//context.Response.Write(@"upload\" + filename);
                break;
        }
    }
    /// <summary>
    /// 10进制或16进制转换为中文
    /// </summary>
    /// <param>要转换的字符串</param>
    /// <param>进制(10或16)</param>
    /// <returns></returns>
    public string ConverToGB(string text, int fromBase)
    {
        string value = text;
        MatchCollection mc;
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        switch (fromBase)
        {
            case 10:
                MatchCollection mc1 = Regex.Matches(text, @"&#([\d]{5})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                foreach (Match _v in mc1)
                {
                    string w = _v.Value.Substring(2);
                    w = Convert.ToString(int.Parse(w), 16);
                    byte[] c = new byte[2];
                    string ss = w.Substring(0, 2);
                    int c1 = Convert.ToInt32(w.Substring(0, 2), 16);
                    int c2 = Convert.ToInt32(w.Substring(2), 16);
                    c[0] = (byte)c2;
                    c[1] = (byte)c1;
                    sb.Append(Encoding.Unicode.GetString(c));
                }
                value = sb.ToString();

break;
            case 16:
                mc = Regex.Matches(text, @"\\u([\w]{2})([\w]{2})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                if (mc != null && mc.Count > 0)
                {

foreach (Match m2 in mc)
                    {
                        string v = m2.Value;
                        string w = v.Substring(2);
                        byte[] c = new byte[2];
                        int c1 = Convert.ToInt32(w.Substring(0, 2), 16);
                        int c2 = Convert.ToInt32(w.Substring(2), 16);
                        c[0] = (byte)c2;
                        c[1] = (byte)c1;
                        sb.Append(Encoding.Unicode.GetString(c));
                    }
                    value = sb.ToString();
                }
                break;
        }
        return value;
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

效果如下图所示:

ASP.NET实现二维码(QRCode)的创建和读取实例

PS:感兴趣的朋友还可参考本站二维码工具:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzzzj.html