一个C#二维码图片识别

https://www.cnblogs.com/xuezhizhang/p/8968515.html

关键是这个 ThoughtWorks.QRCode.Codec;

NuGet直接下载就可以了

/// <summary>
         /// 读取图片文件,识别二维码
 /// </summary>  /// <param name="filePath">图片文件路劲</param>  /// <returns>识别结果字符串</returns>  public static string CodeDecoder(string filePath)   {  string decoderStr;  try   {  if (!System.IO.File.Exists(filePath))//判断有没有需要读取的主文件夹,如果不存在,终止  return null;   Bitmap bitMap = new Bitmap(Image.FromFile(filePath));//实例化位图对象,把文件实例化为带有颜色信息的位图对象  QRCodeDecoder decoder = new QRCodeDecoder();//实例化QRCodeDecoder   //通过.decoder方法把颜色信息转换成字符串信息  decoderStr = decoder.decode(new QRCodeBitmapImage(bitMap), System.Text.Encoding.UTF8);   }  catch (Exception ex)   {  throw ex;  }   return decoderStr;//返回字符串信息   }

猜你喜欢

转载自www.cnblogs.com/LuoEast/p/12692815.html