WPF调用摄像头扫描二维码
在WPF平台
用WPFMediaKit控件调用摄像头扫描二维码,用ZXing的类库去解析,但是一直解析不出来,请高手帮忙!
private RenderTargetBitmap bmp;
private BitmapEncoder encoder;
private MultiFormatReader reader;
if (bmp == null)
{
bmp = new RenderTargetBitmap( (int)m_VideoCaptureElement.ActualWidth,
(int)m_VideoCaptureElement.ActualHeight, 96, 96, PixelFormats.Pbgra32);
bmp.Render(m_VideoCaptureElement);
}
if (encoder == null)
{
encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
}
MemoryStream stream = new MemoryStream();
stream.Seek(0, SeekOrigin.Begin);
encoder.Save(stream);
if (source == null)
{
source = new RGBLuminanceSource(stream.ToArray(), 15, 15, RGBLuminanceSource.BitmapFormat.BGR24);
}
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
reader = new MultiFormatReader();
if (bitmap.BlackMatrix != null)
{
Result result = reader.decode(bitmap);
MessageBox.Show(result.Text);
}