This project has moved and is read-only. For the latest updates, please go here.

Generating a BitmapImage on WP7

Mar 13, 2012 at 1:42 PM

Hi

I want to generate a code 139 barcode into an BitmapImage on the WP7.5 device.  In other implementations the BitMatrix class ports the set_Renamed method which some example use to generate a WriteableBitmap.

Can you provide an example where say the value "CR01234567890" can be rendered into a barcode using your library.  Here is a code snippet:

MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix result = writer.encode("CR01234567890", BarcodeFormat.CODE_128, 100, 100);

// How do you generate a bitmap from a BitMatrix to display on a WP7 device?

Thanks, Craig

Mar 13, 2012 at 11:34 PM

Hi Craig,

please try the new version 0.5.0.0.

With one of my last commits I added the support for the ToBitmap() method on BitMatrix class for Silverlight and Windows Phone.

MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix result = writer.encode("CR01234567890", BarcodeFormat.CODE_128, 100, 100);

// generate a bitmap from a BitMatrix to display on a WP7 device
WriteableBitmap bitmap = result.ToBitmap();


But I didn't try it out on WP7. I wrote only a silverlight demo with encoding support.
You can get the source for the silverlight demo from the repository.

I hope it helps.

Regards
Michael
Mar 14, 2012 at 12:26 AM

Hi Michael

Thanks for the update.  I eventually got am barcode to render late last night night, before getting your reply this morning.  I like the new method ToBitmap().

Using that code sample in our previous posts, I get an IndexOutOfRangeException on the writer.Encode(...) line.  When I use EAN_13 format, replacing the CR to 00 (all numerics), the error doesn't get raised.  Must be something in the encode method of Code 128.

Here's the relevant stack trace:

   at ZXing.OneD.Code128Writer.encode(String contents)
   at ZXing.OneD.OneDimensionalCodeWriter.encode(String contents, BarcodeFormat format, Int32 width, Int32 height, IDictionary`2 hints)
   at ZXing.OneD.Code128Writer.encode(String contents, BarcodeFormat format, Int32 width, Int32 height, IDictionary`2 hints)
   at ZXing.MultiFormatWriter.encode(String contents, BarcodeFormat format, Int32 width, Int32 height, IDictionary`2 hints)
   at ZXing.MultiFormatWriter.encode(String contents, BarcodeFormat format, Int32 width, Int32 height)

Regards

Craig

 

Mar 14, 2012 at 10:43 PM

Thanks for reporting the bug.
I fixed it with revision 74444: http://zxingnet.codeplex.com/SourceControl/changeset/changes/74444

Michael

Mar 15, 2012 at 1:45 AM

Hi Michael

Thanks for the update.  After building fix 74444 I can confirm that the IndexOutOfRangeException is not thrown on encoding a Code139 format.  I'll be testing several other formats over the week or so and will report any issues I encounter using the library on the device.

Good work, Craig