I have been searching for answer for 2 days but i couldn't. That's why i'm posting it here. I followed this tutorial.
I got error bitmap.SetSource(imgStream);
so i changed it to bitmap.SetSource(imgStream.AsStream);
I also got error message on this line. I'm unable to convert pixel to array. Because there is no PixelBuffer
and i cannot use Pixels
var ocrResult = await ocrEngine.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, bitmap.PixelBuffer.ToArray());
So i searched on internet and found this link of stackoverflow.com. So I copied and pasted the following code
public static byte[] ToByteArray(this WriteableBitmap bmp)
{
// Init buffer
int w = bmp.PixelWidth;
int h = bmp.PixelHeight;
int[] p = bmp.Pixels;
int len = p.Length;
byte[] result = new byte[4 * w * h];
// Copy pixels to buffer
for (int i = 0, j = 0; i < len; i++, j += 4)
{
int color = p[i];
result[j + 0] = (byte)(color >> 24); // A
result[j + 1] = (byte)(color >> 16); // R
result[j + 2] = (byte)(color >> 8); // G
result[j + 3] = (byte)(color); // B
}
return result;
}
And then byte[] hello = ByteArrayChange.ToByteArray(bitmap);
var ocrResult = await ocrEngine.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, hello );
I run the code with Device and it gave the exception in App.Xaml.cs
in Application_UnhandledException
Note: I'm developing on Windows Phone 8/8.1 (Silverlight)