[英]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.