QRコードリーダーをやっています。
QR をスキャンすると、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 から戻ると、緑色の画面が表示されます。