i am using the zxing.NET library with the Microsoft Kinect. My problem is, i am getting __after few seconds__ a IndexOutOfRangeException if i want to decode a bitmap. The exception occurs in the method "CovertBitmapToQRcode" if i want to decode the Bitmap. The Resolution of the images from Kinect: 1280x960. Here is the code:
```
void _KinectDevice_AllFramesReady(object sender, AllFramesReadyEventArgs e)
{
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (colorFrame != null)
{
if (framecounter > 1)
{
//Copy the information from the colorFrame into an array
colorFrame.CopyPixelDataTo(this._ColorImagePixelData);
//Show the captured image
ColorImageElement.Source = WriteableBitmap.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, this._ColorImagePixelData, colorFrame.Width * colorFrame.BytesPerPixel);
//Convert the BitmapSouce to a Bitmap
System.Drawing.Bitmap image = BitmapFromSource((BitmapSource)ColorImageElement.Source);
//Show the qrCode in a label
lblQRCode.Content = CovertBitmapToQRcode(image);
framecounter = 0;
}
framecounter++;
}
}
}
//This Method converts a given BitmapSource to a Bitmap.
private System.Drawing.Bitmap BitmapFromSource(BitmapSource bitmapsource)
{
System.Drawing.Bitmap bitmap;
using (MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bitmapsource));
enc.Save(outStream);
bitmap = new System.Drawing.Bitmap(outStream);
}
return bitmap;
}
private string CovertBitmapToQRcode(System.Drawing.Bitmap barcodeBitmap)
{
//Flip the bitmap. Because the captured bitmap from the Kinect is mirrored
barcodeBitmap.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX);
// detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap); __//Here i am getting the Exception__
// do something with the result
if (result != null)
{
return "Decoded QRCode: " + result.Text;
}
return "Decoded QRCode: ";
}
```
Thanks for help and for the great library
Comments: ** Comment from web user: micjahn **
Do you have the chance to dump the picture to disk which is decoded when the exception occurs?
Perhaps if you put a try-catch around the Decode call.
I need the failing picture to reproduce the error.
```
try
{
// detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap); __//Here i am getting the Exception__
}
catch
{
// dump the current bitmap to the hard disk
}
```