C#使用ZXing解码二维码出现中文乱码的问题

发布时间 2023-11-22 11:51:07作者: 因雨
        public string ZXing_Decode(Bitmap barcodeBitmap)
        {
            try
            {
                BarcodeReader reader = new BarcodeReader();
                reader.Options = new ZXing.Common.DecodingOptions
                {
                    CharacterSet = "ISO-8859-1"
                };
                var result = reader.Decode(barcodeBitmap);
                if (result != null && result.Text != null)
                {
                    byte[] isoBytes = Encoding.GetEncoding("ISO-8859-1").GetBytes(result.Text);
                    return Encoding.GetEncoding("gb2312").GetString(isoBytes);
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }