首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用于WinRT的QrCode开源库

用于WinRT的QrCode开源库
EN

Stack Overflow用户
提问于 2012-12-12 21:43:48
回答 3查看 1.2K关注 0票数 2

我需要为我的Windows8应用商店App.Is生成二维码,那里有任何基于Win Rt.的开源二维码库。

EN

回答 3

Stack Overflow用户

发布于 2014-04-15 13:46:04

我使用了Codeplex上的zxing库。

我写的方法如下:

我使用了来自相机的CaptureFileAsync方法的带有存储文件的DecodeQRcode,它返回qrImgage的存储文件。

代码语言:javascript
运行
复制
public async void DecodeQRCode(StorageFile file)
{
        // load a jpeg, be sure to have the Pictures Library capability in your manifest

        var data = await FileIO.ReadBufferAsync(file);

        // create a stream from the file
        var ms = new InMemoryRandomAccessStream();
        var dw = new Windows.Storage.Streams.DataWriter(ms);
        dw.WriteBuffer(data);
        await dw.StoreAsync();
        ms.Seek(0);

        // find out how big the image is, don't need this if you already know
        var bm = new BitmapImage();
        await bm.SetSourceAsync(ms);

        // create a writable bitmap of the right size
        var wb = new WriteableBitmap(bm.PixelWidth, bm.PixelHeight);
        ms.Seek(0);

        // load the writable bitpamp from the stream
        await wb.SetSourceAsync(ms);

        var lsource = new BitmapLuminanceSource(wb);

        var binarizer = new HybridBinarizer(lsource);
        var bbmp = new BinaryBitmap(binarizer);

        var c = new QRCodeReader();
       Result res= c.decode(bbmp);
    }

在拍摄二维码图像时,您必须确保正确裁剪图像,否则无法获得预期结果。

票数 4
EN

Stack Overflow用户

发布于 2012-12-13 14:16:55

我没有用过这个,但是ZXing.Net是....

一个库,支持解码和生成图像中的条形码(如二维码、PDF417、EAN、UPC、Aztec、数据矩阵、Codabar)。

并有可用于WindowsRT (以及电话)的组件

票数 2
EN

Stack Overflow用户

发布于 2014-07-16 16:53:45

您可以使用ZXing.NET:https://zxingnet.codeplex.com/

加载镜像获取二维码结果的代码:

代码语言:javascript
运行
复制
        FileOpenPicker openPicker = new FileOpenPicker();
        openPicker.ViewMode = PickerViewMode.Thumbnail;
        openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
        openPicker.FileTypeFilter.Add(".png");
        openPicker.FileTypeFilter.Add(".jpg");
        openPicker.FileTypeFilter.Add(".bmp");

        StorageFile file = await openPicker.PickSingleFileAsync();
        if (null != file)
        {
            try
            {
                BitmapImage bitmap = new BitmapImage();
                using (IRandomAccessStream fileStream1 = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    bitmap.SetSource(fileStream1);
                }
                using (IRandomAccessStream fileStream2 = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    WriteableBitmap writeableBitmap = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
                    writeableBitmap.SetSource(fileStream2); IBarcodeReader reader = new BarcodeReader();
                    var result = reader.Decode(writeableBitmap);
                    txt1.Text = result.ToString();
                }

            }
            catch (Exception exception)
            {
                //
            }
        }

摄像头获取二维码代码(使用MSDN demo:http://code.msdn.microsoft.com/windowsapps/CameraCaptureUI-Sample-845a53ac和自定义):

代码语言:javascript
运行
复制
    private async void CapturePhoto_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            rootPage.NotifyUser("", NotifyType.StatusMessage);

            // Using Windows.Media.Capture.CameraCaptureUI API to capture a photo
            CameraCaptureUI dialog = new CameraCaptureUI();
            Size aspectRatio = new Size(1, 1);
            dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;

            StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
            if (file != null)
            {
                BitmapImage bitmapImage = new BitmapImage();

                using (IRandomAccessStream fileStream1 = await file.OpenAsync(FileAccessMode.Read))
                {
                    bitmapImage.SetSource(fileStream1);
                }
                CapturedPhoto.Source = bitmapImage;
                ResetButton.Visibility = Visibility.Visible;

                ZXing.BarcodeReader br = new ZXing.BarcodeReader();
                WriteableBitmap wrb = new WriteableBitmap(bitmapImage.PixelWidth, bitmapImage.PixelHeight);
                BitmapImage img = new BitmapImage();
                img.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                using (IRandomAccessStream fileStream2 = await file.OpenAsync(FileAccessMode.Read))
                {
                    wrb.SetSource(fileStream2);
                }
                var res = br.Decode(wrb);
                rootPage.NotifyUser(res.ToString(), NotifyType.ErrorMessage);

            }
            else
            {
                rootPage.NotifyUser("No photo captured.", NotifyType.StatusMessage);
            }
        }
        catch (Exception ex)
        {
            rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage);
        }
    }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13841156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档