【问题标题】:Microsoft OCR: Convert bitmap to pixel array for Windows Phone 8 SilverlightMicrosoft OCR:将位图转换为 Windows Phone 8 Silverlight 的像素阵列
【发布时间】:2014-12-22 13:38:12
【问题描述】:

我已经搜索了 2 天的答案,但我找不到。这就是为什么我把它贴在这里。 我关注了这个tutorial

我收到错误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 的 link。所以我复制并粘贴了以下代码

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 运行代码,它在 App.Xaml.cs 中给出了异常 Application_UnhandledException

注意:我正在 Windows Phone 8/8.1 (Silverlight) 上开发

【问题讨论】:

    标签: c# silverlight windows-phone-8 bytearray microsoft-ocr


    【解决方案1】:

    MSDN 上的 OCR 文档包含有关 Silverlight 应用程序的部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多