我正在使用Microsoft的OCR库,并且在将BitmapImage转换为像素数组时遇到问题。将位图转换为适用于Microsoft OCR的像素阵列#
我为Windows Phone 8制作了这个应用程序,而WriteableBitmap.PixelBuffer.ToArray()不是一个选项,所以我有一个静态函数会将一个普通的BitmapImage改变成一个字节数组,以提供给OCR发动机。嗯,每次我在应用程序崩溃中喂食它。这里有什么问题?
这是我与位图转换器
public static class ByteArrayChange
{
public static byte[] ConvertToBytes(this BitmapImage bitmapImage)
{
byte[] data = null;
using (MemoryStream stream = new MemoryStream())
{
WriteableBitmap wBitmap = new WriteableBitmap(bitmapImage);
wBitmap.SaveJpeg(stream, wBitmap.PixelWidth, wBitmap.PixelHeight, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
data = stream.GetBuffer();
}
return data;
}
}
静态类下面是在OCR方法的代码段是造成应用程序崩溃。
byte[] pa = ByteArrayChange.ConvertToBytes(bitmap);
//Here Is he problem
var ocrResult = await ocrEngine.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, pa);
我在做什么错在这里? 谢谢!
['RecognizeAsync'](http://msdn.microsoft.com/zh-cn/library/windowspreview.media.ocr.ocrengine.recognizeasync.aspx)表示它需要“BGRA8格式的图像字节。 “你传递一个JPG格式的字节数组。 – dbc 2014-10-16 16:14:10
'WriteableBitmap'具有['Pixels'](http://msdn.microsoft.com/zh-cn/library/windows/apps/system.windows.media.imaging.writeablebitmap.pixels%28v=vs.105% 29.aspx)属性。那是你要的吗? – dbc 2014-10-16 16:17:00
Dbc,我该如何让它变成BGRA8格式?而对于WriteableBitmap,它需要PixelBuffer属性,除非像素在WP8框架中是相同的。 – user2536897 2014-10-16 16:19:43