示例#1
0
 public string  DecodeQrImage(string fileName)
 {
     System.Drawing.Image img = System.Drawing.Image.FromFile(fileName);
     Bitmap bmap = new Bitmap(img);
     LuminanceSource source = new RGBLuminanceSource(bmap, bmap.Width, bmap.Height);
     BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
     Result result = new MultiFormatReader().Decode(bitmap);
     return result.Text;
 }
		private Result DecodeInternal(BinaryBitmap image)
		{
			int size = readers.Count;
			for (int i = 0; i < size; i++)
			{
				Reader reader = (Reader) readers[i];
				try
				{
					return reader.Decode(image, hints);
				}
				catch (ReaderException)
				{
					// continue
				}
			}
			
			throw ReaderException.Instance;
		}
		/// <summary> Decode an image using the state set up by calling setHints() previously. Continuous scan
		/// clients will get a <b>large</b> speed increase by using this instead of decode().
		/// 
		/// </summary>
		/// <param name="image">The pixel data to decode
		/// </param>
		/// <returns> The contents of the image
		/// </returns>
		/// <throws>  ReaderException Any errors which occurred </throws>
		public Result DecodeWithState(BinaryBitmap image)
		{
			// Make sure to set up the default state so we don't crash
			if (readers == null)
			{
				Hints = null;
			}
			return DecodeInternal(image);
		}
		/// <summary> Decode an image using the hints provided. Does not honor existing state.
		/// 
		/// </summary>
		/// <param name="image">The pixel data to decode
		/// </param>
		/// <param name="hints">The hints to use, clearing the previous state.
		/// </param>
		/// <returns> The contents of the image
		/// </returns>
		/// <throws>  ReaderException Any errors which occurred </throws>
		public Result Decode(BinaryBitmap image, System.Collections.Hashtable hints)
		{
			Hints = hints;
			return DecodeInternal(image);
		}
		/// <summary> This version of decode honors the intent of Reader.decode(BinaryBitmap) in that it
		/// passes null as a hint to the decoders. However, that makes it inefficient to call repeatedly.
		/// Use setHints() followed by decodeWithState() for continuous scan applications.
		/// 
		/// </summary>
		/// <param name="image">The pixel data to decode
		/// </param>
		/// <returns> The contents of the image
		/// </returns>
		/// <throws>  ReaderException Any errors which occurred </throws>
		public Result Decode(BinaryBitmap image)
		{
			Hints = null;
			return DecodeInternal(image);
		}