Using Zxing.net in IronPython

340 views Asked by At

I need to implement a QR code reader in Calico Python (IronPython) using Zxing.net. When I try to load the barcode image, I get the message:

File "C:\Calico-3.1.0\Calico\zxingTest.py", line 6, in <module> AttributeError: attribute 'Bitmap' of 'namespace#' object is read-only

The image decodes fine with Zbar in Java. The C# sample code I'm basing it on is near the bottom of this page: ZXing.Net at Codeplex

I'm using ZXing.Net 0.14.0.1 and Calico 3.1.0

My code is this:

import clr
import sys
clr.AddReferenceToFileAndPath("C:\\zxing.net\\net4.5\\zxing.dll")
import ZXing as zx
bcr = zx.BarcodeReader()
bcbm = zx.Bitmap.LoadFrom("C:\\temp\\SRQRCode3.png")
result = bcr.Decode(bcbm)

I'm not sure if it is a configuration error, as the IronPython docs suggest, or what.

Thanks in advance.

1

There are 1 answers

0
Simon Opelt On BEST ANSWER

The sample (from http://zxingnet.codeplex.com/) you are basing your snippet on seems outdated and you have some minor errors in translating it from C# to IronPython.

Bitmap is not provided by ZXing but .NET. The properly translated sample should look like:

import clr
import sys
clr.AddReferenceToFileAndPath(r"C:\zxing.net\net4.5\zxing.dll")
import ZXing as zx
from System.Drawing import Bitmap

bcr = zx.BarcodeReader()
bcbm = Bitmap(r"C:\temp\SRQRCode3.png")
result = bcr.Decode(bcbm)
if result is not None:
    print(result.BarcodeFormat.ToString())
    print(result.Text)