[英]How to convert pixel byte array to bitmap image in windows phone 8
[英]Microsoft OCR: Convert bitmap to pixel array for Windows Phone 8 Silverlight
我一直在尋找答案2天,但不能。 這就是為什么我在這里發布它。 我遵循了本教程 。
我收到錯誤bitmap.SetSource(imgStream);
所以我將其更改為bitmap.SetSource(imgStream.AsStream);
我在這條線上也收到錯誤消息。 我無法將像素轉換為數組。 因為沒有PixelBuffer
,所以我無法使用Pixels
var ocrResult = await ocrEngine.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, bitmap.PixelBuffer.ToArray());
所以我在互聯網上搜索,發現了這個stackoverflow.com的鏈接 。 所以我復制並粘貼了以下代碼
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;
}
然后byte[] hello = ByteArrayChange.ToByteArray(bitmap);
var ocrResult = await ocrEngine.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, hello );
我使用Device運行代碼,並在Application_UnhandledException
App.Xaml.cs
中給出了異常
注意:我正在Windows Phone 8 / 8.1(Silverlight)上進行開發
MSDN上的OCR文檔包含有關Silverlight應用程序的部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.