简体   繁体   English

使用C#在Zxing Windows Phone 8应用中杀死相机

[英]Kill camera in zxing Windows Phone 8 app using c#

I am using ZXing for scanning qr code in Windows Phone 8 app. 我正在使用ZXing扫描Windows Phone 8应用中的二维码。 I have some issues related with it. 我有一些与此有关的问题。 1) Unable to kill camera. 1)无法杀死相机。 2) After successfully scanning the bar code I navigate to some other page. 2)成功扫描条形码后,我导航到其他页面。 But when I come back to again scan the qr code, camera is not working. 但是,当我再次扫描二维码时,相机无法正常工作。 In this case i kill my app and again do the whole thing which is surely not a good way. 在这种情况下,我会杀死我的应用程序,然后再次执行整个操作,这肯定不是一个好方法。

Is there anyone who has used Zxing and help me out. 有谁曾经使用过Zxing并帮助过我。

MobileBarcodeScanner scanner; MobileBarcodeScanner扫描仪;

public Login()
{
    InitializeComponent();
    scanner = new MobileBarcodeScanner(this.Dispatcher);
    this.Loaded += MainPage_Loaded;
}

private async void MainPage_Loaded(object sender, RoutedEventArgs e) {
    scanner.UseCustomOverlay = false;
    scanner.UseCustomOverlay = false;
    scanner.TopText = "Hold camera up to barcode";
    scanner.BottomText = "Camera will automatically scan barcode\r\n\r\nPress the 'Back' button to Cancel";

    var result = await scanner.Scan();
    processResult(result);

}

private async void processResult(ZXing.Result result)
{

    if ((result != null) && !string.IsNullOrEmpty(result.Text))
    {
       // some http post call
        NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
    }
    else
    {
        MessageBox.Show("failed");
    }
}

try this code.. it will help for sure 试试这个代码..这肯定会有所帮助

public DesktopLogin()
{
    InitializeComponent();
    scanner = new MobileBarcodeScanner(this.Dispatcher);
    this.Loaded += MainPage_Loaded;
}

private async void MainPage_Loaded(object sender, RoutedEventArgs e) {
    scanner.UseCustomOverlay = false;
    scanner.UseCustomOverlay = false;
    scanner.TopText = "Hold camera up to barcode";
    scanner.BottomText = "Camera will automatically scan barcode\r\n\r\nPress the 'Back' button to Cancel";

    //Start scanning
    await scanner.Scan().ContinueWith(t =>
    {
        if (t.Result != null)
            processResult(t.Result);
    });
}

private void processResult(ZXing.Result result)
{
    if ((result != null) && !string.IsNullOrEmpty(result.Text))
    {
        string qrCode = result.Text;

        this.Dispatcher.BeginInvoke(() =>
        {
            MessageBox.Show("QR Code is " + qrCode);
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            NavigationService.RemoveBackEntry();
        });
    }
    else
    {
        MessageBox.Show("Scanning Canceled!");
    }   
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#Windows Phone ZXing绿屏 - c# windows phone zXing green screen 使用ZXing 2.0 C#Port在Windows Phone 7.1上生成QR代码 - Generating QR code on Windows Phone 7.1 using ZXing 2.0 C# Port Windows Mobile:使用C#的手机摄像头 - Windows Mobile: using phone's camera with C# 从现有的相机应用程序Windows Phone 8.1运行时C中获取图片 - get Picture from exising camera app Windows Phone 8.1 runtime c# 如何从我的Windows Phone 8应用程序(XAML和C#)访问相机并将拍摄的照片保存在确定的文件夹中? - How to access the camera from my Windows Phone 8 app (XAML and C#) and save the taken picture in a determined folder? 如何使用C#在Windows Phone应用中添加列表项? - How to add list items in windows phone app using c#? 使用C#访问Windows Phone APP上的HTML元素 - Access to HTML Elements on Windows Phone APP using C# 使用XAML和C#设置Windows Phone 8应用程序的计时器 - Set Timer For Windows phone 8 App Using XAML With C# 如何使用C#在Windows Phone中使用前置摄像头捕获视频 - How to capture video using front camera in windows phone using c# 如何使用Windows Phone App在Windows Phone 8的C#中暂停 - How to do a pause in C# for Windows Phone 8 using Windows Phone App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM