How to create a QR code image using Zxing on Windows Phone 8.1

Richard Fraser Vanneck

I have been searching the web for examples of code using Zxing in Windows Phone 8.1 but have come up short. I am writing in C# and below is my code, which I have come up with so far:

BarcodeWriter _writer = new BarcodeWriter();

var hello =  _writer.Encoder.encode("HelloWhoIsThere", BarcodeFormat.QR_CODE, 350, 350);

ZXing.Common.BitMatrix matrix = new ZXing.Common.BitMatrix(359,350);

ZXing.Rendering.PixelData rendered = _writer.Renderer.Render(hello, BarcodeFormat.CODE_128, "HelloWhoIsThere");

byte[] byte1 = rendered.Pixel;

Stream memStream = new MemoryStream(byte1);

memStream.Position = 0;

BitmapDecoder decoder = await BitmapDecoder.CreateAsync(memStream.AsRandomAccessStream());

// create a new stream and encoder for the new image
InMemoryRandomAccessStream mrAccessStream = new InMemoryRandomAccessStream();
BitmapEncoder encoder = await BitmapEncoder.CreateForTranscodingAsync(mrAccessStream, decoder);

// convert the bitmap to a 400px by 400px bitmap
encoder.BitmapTransform.ScaledHeight = 350;
encoder.BitmapTransform.ScaledWidth = 350;

// write out to the stream
try
{
    await encoder.FlushAsync();
}
catch (Exception ex)
{
    string s = ex.ToString();
}

// render the stream to the screen
WB = new WriteableBitmap(350, 350);
WB.SetSource(mrAccessStream);
if (WB != null)
{
    SelectedImage.Source = WB;
}
if (WB == null)
{
    txtDecoderContent.Text = "WB = null";
}

I Get an error of "System.NullReferenceException: Object reference not set to an instance of an object." which I think happens when I try and convert the rendered QR code into byte[].

I would appreciate any help, Thanks

kober

usings

using ZXing;
using Windows.UI.Xaml.Media.Imaging;

code

IBarcodeWriter writer = new BarcodeWriter
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Height = 300,
                    Width = 300
                }
            };
var result = writer.Write("generator works");
var wb = result.ToBitmap() as WriteableBitmap;

//add to image component
image.Source = wb;

much simpler and working (tested in one of my apps)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to recognize QR code from image using ZXing library?

From Dev

Find QR code in image and decode it using Zxing

From Dev

Scanning QR Image With Zxing from Windows Phone Image Library

From Dev

Scanning QR Image With Zxing from Windows Phone Image Library

From Dev

Reading QR Code & BarCode in windows phone 8

From Dev

Android I use Zxing Qr code, how to scan local Qr code image?

From Dev

Android Generate QR code and Barcode using Zxing

From Dev

QR code reader for Windows Phone

From Dev

How to scan QR Code in Windows Phone 8.1 using Phonegap/Cordova/WinJS/HTML/CSS/JS?

From Dev

QR Code Scanning on Windows Phone 8.1 using HTML, CSS and JS

From Dev

how to create multiple table in SQLite using properties in windows phone 8

From Dev

I am not able see generated QR Code Image in Xamarin using ZXing.NET.Mobile

From Dev

How to scan a QR code in a Windows Phone 8.1 App? (not silverlight app)?

From Dev

How to scan a QR code in a Windows Phone 8.1 App? (not silverlight app)?

From Dev

QR Code is not recognized by ZXing

From Dev

Add custom image or text to QR code generated by ZXing.Net

From Dev

How to rotate an image in Windows Phone 8?

From Dev

How to set background image in Windows Phone 8?

From Dev

How to create a Windows Phone 8 app package?

From Dev

QR-encode a String to Image in Android project using zxing

From Dev

How to set a background image by code on windows phone?

From Dev

How to set a background image by code on windows phone?

From Dev

Decode QR code from Byte[] using ZXing in C#

From Dev

Android: Generated QR code using Zxing has margins (is not fit to the area)

From Dev

How to track the data after scanning in zxing QR code library?

From Dev

ZXing QR Code/Barcode scanning

From Dev

how to embed a QR code with existing image using java script?

From Dev

Create HyperlinkButton with text wrapping in code behind (Windows Phone 8)

From Dev

How we can update Windows Phone 8 Flip Tile back image in a 5 minute interval using ShellTileSchedule?

Related Related

  1. 1

    How to recognize QR code from image using ZXing library?

  2. 2

    Find QR code in image and decode it using Zxing

  3. 3

    Scanning QR Image With Zxing from Windows Phone Image Library

  4. 4

    Scanning QR Image With Zxing from Windows Phone Image Library

  5. 5

    Reading QR Code & BarCode in windows phone 8

  6. 6

    Android I use Zxing Qr code, how to scan local Qr code image?

  7. 7

    Android Generate QR code and Barcode using Zxing

  8. 8

    QR code reader for Windows Phone

  9. 9

    How to scan QR Code in Windows Phone 8.1 using Phonegap/Cordova/WinJS/HTML/CSS/JS?

  10. 10

    QR Code Scanning on Windows Phone 8.1 using HTML, CSS and JS

  11. 11

    how to create multiple table in SQLite using properties in windows phone 8

  12. 12

    I am not able see generated QR Code Image in Xamarin using ZXing.NET.Mobile

  13. 13

    How to scan a QR code in a Windows Phone 8.1 App? (not silverlight app)?

  14. 14

    How to scan a QR code in a Windows Phone 8.1 App? (not silverlight app)?

  15. 15

    QR Code is not recognized by ZXing

  16. 16

    Add custom image or text to QR code generated by ZXing.Net

  17. 17

    How to rotate an image in Windows Phone 8?

  18. 18

    How to set background image in Windows Phone 8?

  19. 19

    How to create a Windows Phone 8 app package?

  20. 20

    QR-encode a String to Image in Android project using zxing

  21. 21

    How to set a background image by code on windows phone?

  22. 22

    How to set a background image by code on windows phone?

  23. 23

    Decode QR code from Byte[] using ZXing in C#

  24. 24

    Android: Generated QR code using Zxing has margins (is not fit to the area)

  25. 25

    How to track the data after scanning in zxing QR code library?

  26. 26

    ZXing QR Code/Barcode scanning

  27. 27

    how to embed a QR code with existing image using java script?

  28. 28

    Create HyperlinkButton with text wrapping in code behind (Windows Phone 8)

  29. 29

    How we can update Windows Phone 8 Flip Tile back image in a 5 minute interval using ShellTileSchedule?

HotTag

Archive