Zxing中文亂碼的簡單解決辦法


網上的解決辦法都是更改源碼來實現,實際上看源碼就知道如果在encoder的時候,如果添加了編碼,就會用編碼來替代默認的編碼。

 public static Bitmap ContentToQRBitmap(string content, int size)
        {
            Hashtable hints = new Hashtable();
       
            hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");
      
            ByteMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, size, size,hints);
            int width = matrix.Width;
            int height = matrix.Height;
           
            Bitmap bmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    bmap.SetPixel(x, y, matrix.get_Renamed(x, y) != -1 ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF"));
                }
            }
            return bmap;
        }

其中,hints的傳入是關鍵,不同版本的hints有不同的格式,有的是hashtable,有的是Dictionary.看你用的版本。我的版本是zxing 2.0


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM