我使用 PhotoCamera 类在带有 zxing 的 pre window phone 8.1 上使用了以下代码。现在我不确定这是否仍然适用于您的目的,但这是LuminanceSource
派生类。
internal class PhotoCameraLuminanceSource : LuminanceSource
{
public byte[] PreviewBufferY { get; private set; }
public PhotoCameraLuminanceSource(int width, int height)
: base(width, height)
{
PreviewBufferY = new byte[width * height];
}
public override byte[] Matrix
{
get { return (byte[])(Array)PreviewBufferY; }
}
public override byte[] getRow(int y, byte[] row)
{
if (row == null || row.Length < Width)
{
row = new byte[Width];
}
for (int i = 0; i < Height; i++)
row[i] = (byte)PreviewBufferY[i * Width + y];
return row;
}
}
然后像这样使用它。
PhotoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
var binarizer = new HybridBinarizer(_luminance);
var binBitmap = new BinaryBitmap(binarizer);
//Use readers to decode possible barcodes.
var result = _QRCodeReader.decode(binBitmap);
_luminance
类型在哪里PhotoCameraLuminanceSource