Skip to content

Commit f6939f1

Browse files
author
clowwindy
committed
qrcode scan works
1 parent 7927811 commit f6939f1

17 files changed

+3060
-22
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* Copyright 2012 ZXing.Net authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System;
18+
#if !PORTABLE
19+
#if !(SILVERLIGHT || NETFX_CORE)
20+
#if !UNITY
21+
using System.Drawing;
22+
using ZXing.QrCode;
23+
#else
24+
using UnityEngine;
25+
#endif
26+
#elif NETFX_CORE
27+
using Windows.UI.Xaml.Media.Imaging;
28+
#else
29+
using System.Windows.Media.Imaging;
30+
#endif
31+
#endif
32+
#if MONOANDROID
33+
using Android.Graphics;
34+
#endif
35+
36+
namespace ZXing
37+
{
38+
/// <summary>
39+
/// A smart class to decode the barcode inside a bitmap object
40+
/// </summary>
41+
#if MONOTOUCH
42+
public class BarcodeReader : BarcodeReaderGeneric<MonoTouch.UIKit.UIImage>, IBarcodeReader, IMultipleBarcodeReader
43+
{
44+
private static readonly Func<MonoTouch.UIKit.UIImage, LuminanceSource> defaultCreateLuminanceSource =
45+
(img) => new RGBLuminanceSource(img);
46+
#else
47+
#if !PORTABLE
48+
#if !(SILVERLIGHT || NETFX_CORE)
49+
#if !UNITY
50+
public class BarcodeReader : BarcodeReaderGeneric<Bitmap>, IBarcodeReader
51+
{
52+
private static readonly Func<Bitmap, LuminanceSource> defaultCreateLuminanceSource =
53+
(bitmap) => new BitmapLuminanceSource(bitmap);
54+
#else
55+
public class BarcodeReader : BarcodeReaderGeneric<Color32[]>, IBarcodeReader, IMultipleBarcodeReader
56+
{
57+
private static readonly Func<Color32[], int, int, LuminanceSource> defaultCreateLuminanceSource =
58+
(rawColor32, width, height) => new Color32LuminanceSource(rawColor32, width, height);
59+
#endif
60+
#else
61+
public class BarcodeReader : BarcodeReaderGeneric<WriteableBitmap>, IBarcodeReader, IMultipleBarcodeReader
62+
{
63+
private static readonly Func<WriteableBitmap, LuminanceSource> defaultCreateLuminanceSource =
64+
(bitmap) => new BitmapLuminanceSource(bitmap);
65+
#endif
66+
#else
67+
public class BarcodeReader : BarcodeReaderGeneric<byte[]>, IBarcodeReader, IMultipleBarcodeReader
68+
{
69+
private static readonly Func<byte[], LuminanceSource> defaultCreateLuminanceSource =
70+
(data) => null;
71+
#endif
72+
#endif
73+
/// <summary>
74+
/// Initializes a new instance of the <see cref="BarcodeReader"/> class.
75+
/// </summary>
76+
public BarcodeReader()
77+
: this(new QRCodeReader(), defaultCreateLuminanceSource, null)
78+
{
79+
}
80+
81+
/// <summary>
82+
/// Initializes a new instance of the <see cref="BarcodeReader"/> class.
83+
/// </summary>
84+
/// <param name="reader">Sets the reader which should be used to find and decode the barcode.
85+
/// If null then MultiFormatReader is used</param>
86+
/// <param name="createLuminanceSource">Sets the function to create a luminance source object for a bitmap.
87+
/// If null, an exception is thrown when Decode is called</param>
88+
/// <param name="createBinarizer">Sets the function to create a binarizer object for a luminance source.
89+
/// If null then HybridBinarizer is used</param>
90+
public BarcodeReader(Reader reader,
91+
#if MONOTOUCH
92+
Func<MonoTouch.UIKit.UIImage, LuminanceSource> createLuminanceSource,
93+
#elif MONOANDROID
94+
Func<Android.Graphics.Bitmap, LuminanceSource> createLuminanceSource,
95+
#else
96+
#if !(SILVERLIGHT || NETFX_CORE)
97+
#if !UNITY
98+
#if !PORTABLE
99+
Func<Bitmap, LuminanceSource> createLuminanceSource,
100+
#else
101+
Func<byte[], LuminanceSource> createLuminanceSource,
102+
#endif
103+
#else
104+
Func<Color32[], int, int, LuminanceSource> createLuminanceSource,
105+
#endif
106+
#else
107+
Func<WriteableBitmap, LuminanceSource> createLuminanceSource,
108+
#endif
109+
#endif
110+
Func<LuminanceSource, Binarizer> createBinarizer
111+
)
112+
: base(reader, createLuminanceSource ?? defaultCreateLuminanceSource, createBinarizer)
113+
{
114+
}
115+
116+
/// <summary>
117+
/// Initializes a new instance of the <see cref="BarcodeReader"/> class.
118+
/// </summary>
119+
/// <param name="reader">Sets the reader which should be used to find and decode the barcode.
120+
/// If null then MultiFormatReader is used</param>
121+
/// <param name="createLuminanceSource">Sets the function to create a luminance source object for a bitmap.
122+
/// If null, an exception is thrown when Decode is called</param>
123+
/// <param name="createBinarizer">Sets the function to create a binarizer object for a luminance source.
124+
/// If null then HybridBinarizer is used</param>
125+
public BarcodeReader(Reader reader,
126+
#if MONOTOUCH
127+
Func<MonoTouch.UIKit.UIImage, LuminanceSource> createLuminanceSource,
128+
#elif MONOANDROID
129+
Func<Android.Graphics.Bitmap, LuminanceSource> createLuminanceSource,
130+
#else
131+
#if !(SILVERLIGHT || NETFX_CORE)
132+
#if !UNITY
133+
#if !PORTABLE
134+
Func<Bitmap, LuminanceSource> createLuminanceSource,
135+
#else
136+
Func<byte[], LuminanceSource> createLuminanceSource,
137+
#endif
138+
#else
139+
Func<Color32[], int, int, LuminanceSource> createLuminanceSource,
140+
#endif
141+
#else
142+
Func<WriteableBitmap, LuminanceSource> createLuminanceSource,
143+
#endif
144+
#endif
145+
Func<LuminanceSource, Binarizer> createBinarizer,
146+
Func<byte[], int, int, RGBLuminanceSource.BitmapFormat, LuminanceSource> createRGBLuminanceSource
147+
)
148+
: base(reader, createLuminanceSource ?? defaultCreateLuminanceSource, createBinarizer, createRGBLuminanceSource)
149+
{
150+
}
151+
}
152+
}

0 commit comments

Comments
 (0)