Пример #1
0
        private string QRDecode(string data)
        {
            byte[] bytes = Convert.FromBase64String(data);

            Bitmap bitmap = new Bitmap(new MemoryStream(bytes));

            var barcodeReader = new ZXing.ZKWeb.BarcodeReader();

            barcodeReader.Options = new DecodingOptions
            {
                CharacterSet = "UTF-8"
            };
            Result result = barcodeReader.Decode(bitmap);

            return(result == null ? null : result.Text);
        }
Пример #2
0
        /// <summary>
        /// 读取二维码或者条形码从图片
        /// </summary>
        /// <param name="imgFile"></param>
        /// <returns></returns>
        public static string ReadFromImage(string imgFile)
        {
            if (string.IsNullOrWhiteSpace(imgFile))
            {
                return("");
            }
            Image  img = Image.FromFile(imgFile);
            Bitmap b   = new Bitmap(img);

            //该类名称为BarcodeReader,可以读二维码和条形码
            var zzb = new ZXing.ZKWeb.BarcodeReader();

            zzb.Options = new DecodingOptions
            {
                CharacterSet = "UTF-8"
            };
            Result r          = zzb.Decode(b);
            string resultText = r.Text;

            b.Dispose();
            img.Dispose();

            return(resultText);
        }