c# windows phone zXing green screen
本文关键字:green screen zXing phone windows | 更新日期: 2023-09-27 18:34:11
我在做一个二维码阅读器。
当我扫描二维码时,我想在另一个名为 reader.xaml 的页面中导航,在那里我做了一些事情。
但是当我按下按钮 返回 从 reader.xaml 到初始页面时......有时出现绿屏,我必须重新启动我的 Lumia 920...
我不明白为什么?!?!
我正在使用zxing库。
有人可以帮我
public MainPage()
{
InitializeComponent();
/* CHECKING CONNECTION STATUS */
bool isConnected = NetworkInterface.GetIsNetworkAvailable();
if (!isConnected)
{
MessageBox.Show("No internet connection", MessageBoxButton.OK);
Microsoft.Xna.Framework.Game game = new Microsoft.Xna.Framework.Game();
game.Exit();
}
//reading value
if (IsolatedStorageSettings.ApplicationSettings.Contains("idDevice"))
{
idDevice = (string)IsolatedStorageSettings.ApplicationSettings["idDevice"];
}
else
{
//insert
Random random = new Random();
var duration = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0);
long ticks = (long)duration.TotalSeconds;
idDevice = ticks.ToString() + "-" + random.Next(1, 2000000001).ToString();
IsolatedStorageSettings.ApplicationSettings.Add("idDevice", idDevice);
IsolatedStorageSettings.ApplicationSettings.Save();
}
_timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(2) };
GameTimer gameTimer = new GameTimer();
gameTimer.UpdateInterval = TimeSpan.FromMilliseconds(33);
// Call FrameworkDispatcher.Update to update the XNA Framework internals.
gameTimer.Update += delegate { try { FrameworkDispatcher.Update(); } catch { } };
// Start the GameTimer running.
if (Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Playing || Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Paused)
{
if (MessageBox.Show("Media is currently playing, do you want to stop it?", "Stop Player", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
try
{
gameTimer.Stop();
Microsoft.Xna.Framework.Media.MediaPlayer.Stop();
AudioPlayerS.Source = new Uri("/audioProva.mp3", UriKind.Relative);
}
catch { }
}
else
{
Microsoft.Xna.Framework.Game game = new Microsoft.Xna.Framework.Game();
game.Exit();
}
}
// Prime the pump or we'll get an exception.
FrameworkDispatcher.Update();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
_photoCamera = new PhotoCamera();
_photoCamera.Initialized += OnPhotoCameraInitialized;
_previewVideo.SetSource(_photoCamera);
//CameraButtons.ShutterKeyHalfPressed += (o, arg) => _photoCamera.Focus();
try
{
if (_photoCamera.IsFocusSupported)
{
_timer.Tick += (o, arg) => { try { _photoCamera.FlashMode = FlashMode.Off; _photoCamera.Focus(); } catch (Exception) { } };
_photoCamera.AutoFocusCompleted += (o, arg) => { if (arg.Succeeded) ScanPreviewBuffer(); };
}
else
{
_timer.Tick += (o, arg) => ScanPreviewBuffer();
}
}
catch
{
_timer.Tick += (o, arg) => ScanPreviewBuffer();
}
base.OnNavigatedTo(e);
}
private void OnPhotoCameraInitialized(object sender, CameraOperationCompletedEventArgs e)
{
int width = Convert.ToInt32(_photoCamera.PreviewResolution.Width);
int height = Convert.ToInt32(_photoCamera.PreviewResolution.Height);
_luminance = new PhotoCameraLuminanceSource(width, height);
_reader = new QRCodeReader();
Dispatcher.BeginInvoke(() =>
{
_timer.Start();
_previewTransform.Rotation = _photoCamera.Orientation;
});
}
private void ScanPreviewBuffer()
{
try
{
_photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
var binarizer = new HybridBinarizer(_luminance);
var binBitmap = new BinaryBitmap(binarizer);
var result = _reader.decode(binBitmap);
Dispatcher.BeginInvoke(() => CheckQr(result.Text));
}
catch
{
}
}
private void CheckQr(string link)
{
if (IsValidHttpUri(link) == false)
{
MessageBox.Show("error", MessageBoxButton.OK);
return;
}
else
{
_timer.Stop();
try
{
_photoCamera.CancelFocus();
}
catch
{
}
NavigationService.Navigate(new Uri("/reader.xaml?linkQr=" + link, UriKind.Relative));
}
}
当我从reader.xaml回来时,出现绿屏。
https://zxingnet.codeplex.com/discussions/407383
问题中提供的链接包含解决方案,您需要
"你是否试图在OnNavigatedFrom中处理()摄影机?"