Reputation: 813
I am using the ZXing.Net library(0.16.4) to encode and decode a QR Code. I got the reference of how to decode the qr code from here: C# with ZXing.Net: Decoding the QR code
Code:
Bitmap image = (Bitmap)Bitmap.FromFile(@"file.png");
byte[] bytes = File.ReadAllBytes(@"file.png");
try
{
using (image)
{
LuminanceSource source;
source = new BitmapLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result = new MultiFormatReader().decode(bitmap);
if (result != null)
{
//... code found
var data = result.Text.Split(Environment.NewLine);
}
else
{
//... no code found
}
}
}
catch (Exception exception)
{
throw new Exception("Cannot decode the QR code " + exception.Message);
}
Here the code throws the compile time error on BitmapLuminanceSource
The type or namespace name 'BitmapLuminanceSource' could not be found (are you missing a using directive or an assembly reference?
I have already installed ZXing.Net package here, I am not able to understand, why this class reference is not working here.
To make the code work, I have copied this class from git from here: https://github.com/micjahn/ZXing.Net/blob/master/Source/lib/BitmapLuminanceSource.cs
Upvotes: 4
Views: 6961
Reputation: 113
This class is not available in .NET Core version of the library (but will be, some time soon). micjahn, the author of ZXing.Net, advises to utilize some of the bindings listed here https://www.nuget.org/packages?q=ZXing.Net.Bindings I picked ZKWeb and my initialisation code looks like this:
var bitMap = (System.DrawingCore.Bitmap)System.DrawingCore.Bitmap.FromStream(stream);
var source = new ZXing.ZKWeb.BitmapLuminanceSource(bitMap);
var binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
The original answer is here. Some additional information.
Upvotes: 1
Reputation: 143
I was running into the same issue on Xamarin.Android, I installed the NuGet to my solution: https://www.nuget.org/packages/ZXing.Net/
I'd make sure all the references to the package files are correct. If you are using Visual Studio this is done for you, just be sure to add the Zxing.Net NuGet Package as the Zxing.Net.Mobile/Zxing.Net.Forms don't have the BitmapLuminanceSource method.
Upvotes: 0