diff --git a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj index b4446480..f705103d 100644 --- a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj +++ b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj @@ -248,6 +248,9 @@ + + QRScanner.xaml + Code @@ -351,6 +354,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + @@ -457,6 +464,9 @@ False ..\packages\WPtoolkit.4.2013.08.16\lib\wp8\Microsoft.Phone.Controls.Toolkit.dll + + ..\packages\ZXing.Net.0.11.0.1\lib\wp8\zxing.wp8.0.dll + diff --git a/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml b/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml index 6c5236ad..94181ca5 100644 --- a/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml +++ b/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml @@ -12,6 +12,9 @@ + + + diff --git a/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs b/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs index b8366f53..23bebb98 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs +++ b/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs @@ -681,6 +681,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Die primäre Kamera steht nicht zur Verfügung. ähnelt. + /// + public static string PrimCamNotSupported { + get { + return ResourceManager.GetString("PrimCamNotSupported", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Lehrstühle ähnelt. /// @@ -690,6 +699,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die ... suche ähnelt. + /// + public static string QRReader_Search { + get { + return ResourceManager.GetString("QRReader_Search", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die LeftToRight ähnelt. /// diff --git a/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx b/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx index b892c458..70135f6d 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx @@ -406,5 +406,10 @@ Es konnte kein neuer Inhalt aus den Web geladen werden + + Die primäre Kamera steht nicht zur Verfügung. + + + ... suche \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Utility/QRScanner/QRScanner.xaml b/CampusAppWP8/CampusAppWP8/Utility/QRScanner/QRScanner.xaml new file mode 100644 index 00000000..d20dce55 --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Utility/QRScanner/QRScanner.xaml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Utility/QRScanner/QRScanner.xaml.cs b/CampusAppWP8/CampusAppWP8/Utility/QRScanner/QRScanner.xaml.cs new file mode 100644 index 00000000..aad8fca5 --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Utility/QRScanner/QRScanner.xaml.cs @@ -0,0 +1,224 @@ +//----------------------------------------------------------------------------- +// +// Company copyright tag. +// +// fiedlchr +// 15.08.2013 +// +// This Class uses the ZXing library, which is under the Apache License 2.0. +// +// Therefor, see: +// http://zxingnet.codeplex.com/license +// http://www.apache.org/licenses/LICENSE-2.0 +// +//----------------------------------------------------------------------------- +namespace CampusAppWP8.Utility.QRScanner +{ + using System; + using System.Threading; + using System.Windows; + using System.Windows.Media.Imaging; + using CampusAppWP8.Resources; + using Microsoft.Devices; + using Microsoft.Phone.Controls; + using ZXing; + + /// + /// QR Code scanner. + /// + public partial class QRScanner : PhoneApplicationPage + { + /// The camera object. + private PhotoCamera cam = null; + + /// Thread for transfer the preview image to the reader. + private Thread captureThread = null; + + /// For ending the thread. + private volatile bool captureThreadExit = false; + + /// QR reader object. + private IBarcodeReader barcodeReader = null; + + /// Bitmap for transfer the camera image to the reader. + private WriteableBitmap bit = null; + + /// true if this object is in autofocus. + private bool isInAutofocus = false; + + /// Initializes a new instance of the class. + public QRScanner() + { + this.InitializeComponent(); + this.barcodeReader = new BarcodeReader(); + } + + /// + /// Is called when this page will become the current page of a frame. + /// + /// event args. + protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) + { + if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) + { + this.cam = new PhotoCamera(CameraType.Primary); + this.cam.Initialized += new EventHandler(this.Cam_Initialized); + this.cam.AutoFocusCompleted += new EventHandler(this.Cam_AutoFocusCompl); + this.bit = new WriteableBitmap((int)this.cam.PreviewResolution.Width, (int)this.cam.PreviewResolution.Height); + + this.camViewBrush.SetSource(this.cam); + this.isInAutofocus = false; + } + else + { + this.Dispatcher.BeginInvoke(delegate + { + this.scannText.Text = AppResources.PrimCamNotSupported; + }); + } + } + + /// + /// Is called when this page will not be the current page of a frame. + /// + /// event args. + protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e) + { + if (this.cam != null) + { + this.captureThreadExit = true; + this.captureThread.Join(); + + this.cam.Dispose(); + + this.bit = null; + } + } + + /// + /// Is called after the orientation has changed. + /// + /// event args. + protected override void OnOrientationChanged(OrientationChangedEventArgs e) + { + base.OnOrientationChanged(e); + + switch (e.Orientation) + { + case PageOrientation.Landscape: + this.camViewBrushTransform.Rotation = 0; + break; + case PageOrientation.LandscapeLeft: + this.camViewBrushTransform.Rotation = 0; + break; + case PageOrientation.LandscapeRight: + this.camViewBrushTransform.Rotation = 180; + break; + case PageOrientation.Portrait: + this.camViewBrushTransform.Rotation = 90; + break; + case PageOrientation.PortraitUp: + this.camViewBrushTransform.Rotation = 90; + break; + case PageOrientation.PortraitDown: + this.camViewBrushTransform.Rotation = 270; + break; + } + } + + /// + /// Event handler. Called by Cam for initialized events. + /// + /// Source of the event. + /// Camera operation completed event information. + private void Cam_Initialized(object sender, Microsoft.Devices.CameraOperationCompletedEventArgs e) + { + if (e.Succeeded) + { + this.cam.Focus(); + + this.captureThreadExit = false; + this.captureThread = new Thread(this.CaptureThreadFunc); + this.captureThread.Start(); + } + } + + /// + /// Event handler. Called by Cam for automatic focus completed events. + /// + /// Source of the event. + /// Camera operation completed event information. + private void Cam_AutoFocusCompl(object sender, CameraOperationCompletedEventArgs e) + { + this.isInAutofocus = false; + } + + /// + /// Event handler. Called by CamView for tap events. + /// + /// Source of the event. + /// Gesture event information. + private void CamView_Tap(object sender, System.Windows.Input.GestureEventArgs e) + { + if (this.cam != null && this.isInAutofocus == false) + { + if (this.cam.IsFocusAtPointSupported == true) + { + Point pos = e.GetPosition(this.camView); + + this.cam.FocusAtPoint( + pos.Y / this.camView.ActualHeight, + 1.0 - (pos.X / this.camView.ActualWidth)); + + this.isInAutofocus = true; + } + else if (this.cam.IsFocusSupported == true) + { + this.cam.Focus(); + } + } + } + + /// + /// Executes the capture image action. + /// + /// The image. + /// The width. + /// The height. + private void OnCaptureImage(int[] img, int width, int height) + { + Array.Copy(img, this.bit.Pixels, img.Length); + + var result = this.barcodeReader.Decode(this.bit); + + if (result != null) + { + Dispatcher.BeginInvoke(delegate + { + this.scannText.Text = result.Text; + }); + } + } + + /// + /// Capture thread function. + /// + private void CaptureThreadFunc() + { + Size resolution = this.cam.PreviewResolution; + int[] buffer = new int[(int)(resolution.Height * resolution.Width)]; + + while (!this.captureThreadExit) + { + if (this.isInAutofocus == false) + { + this.cam.GetPreviewBufferArgb32(buffer); + + this.OnCaptureImage(buffer, (int)resolution.Width, (int)resolution.Height); + } + + System.Threading.Thread.Sleep(1000); + } + } + } +} \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/packages.config b/CampusAppWP8/CampusAppWP8/packages.config index 145c4038..abf42a7a 100644 --- a/CampusAppWP8/CampusAppWP8/packages.config +++ b/CampusAppWP8/CampusAppWP8/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file