【问题标题】:Convert WriteableBitmap of win phone 8.1 (silverlight) to BinaryBitmap of com.google.zxingwin phone 8.1 (silverlight) 的 WriteableBitmap 转换为 com.google.zxing 的 BinaryBitmap
【发布时间】:2016-04-08 04:51:01
【问题描述】:

花了将近一天的时间搜索,但找不到合适的解决方案。我正在为基于 Silverlight 的 win 8.1 手机应用程序开发 QR 阅读模块(不是 win 8.1 手机本机)

我正在使用 zxing lib 添加完整的 QR 模块。我已经达到了从相机(MediaCapture)获得图像的地步,对象是 WriteableBitmap,我想使用 api QRCodeReader.decode(BinaryBitmap bb)。

我已尝试使用大多数文章所述的 RGBLuminanceSource,但它适用于本机应用程序(因为它需要引用 System.Windows,这对于基于 Silverlight 的应用程序无效。

有人可以指导我将 WriteableBitmap 转换为 BinaryBitmap 吗?

【问题讨论】:

    标签: c# silverlight zxing win-phone-silverlight-8.1


    【解决方案1】:

    我使用 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

    【讨论】:

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