2014-01-25 74 views
2

我一直在嘗試一段時間,以找到一個體面的教程,如何可以與Windows Phone 8的QR碼。不幸的是,所有這些,(至少我發現,這是一個很大的負載),是爲了WP7,並沒有工作。在Windows Phone 8上的QR掃描

他們中的一些需要PhotoLuminance對象,這是不可用ZXing.net庫中。

我覺得我最大的問題是,我不知道如何從相機獲取的ImageStream,在旅途中,然後掃描它的每一秒左右。

我需要流利的東西,而不必啓動cameratask :)。

現在,我使用VideoBrush組件捕獲圖像到矩形,因此從相機檢索數據正在工作。

camera = new PhotoCamera(CameraType.Primary); 
viewfinderBrush.SetSource(camera); 

我用這個作爲最後的手段,我真希望有人在那裏的樣本代碼或一個想法,我應該如何處理這個

回答

0

嘗試用ZXing.Net庫下面給出的代碼。

XAML

<Grid x:Name="grdCamera"> 
    <Rectangle x:Name="_previewRect" 
      Margin="0" 
      Height="800" 
      Width="600" 
      HorizontalAlignment="Center" 
      VerticalAlignment="Center"> 
     <Rectangle.Fill> 
      <VideoBrush x:Name="_previewVideo"> 
       <VideoBrush.RelativeTransform> 
        <CompositeTransform 
        x:Name="_previewTransform" CenterX=".5" CenterY=".5" /> 
       </VideoBrush.RelativeTransform> 
      </VideoBrush> 
     </Rectangle.Fill> 
    </Rectangle> 
</Grid> 

C#

private readonly DispatcherTimer _timer; 
private PhotoCameraLuminanceSource _luminance; 
private QRCodeReader _reader; 
private PhotoCamera _photoCamera; 

//Constructor 
public ScanPage() 
{ 
    InitializeComponent(); 

    _timer = new DispatcherTimer(); 
    _timer.Interval = TimeSpan.FromMilliseconds(250); 
    _timer.Tick += (o, arg) => ScanPreviewBuffer(); 
} 

protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    _photoCamera = new PhotoCamera(); 
    _photoCamera.Initialized += OnPhotoCameraInitialized; 
    _previewVideo.SetSource(_photoCamera); 

    CameraButtons.ShutterKeyHalfPressed += (o, arg) => _photoCamera.Focus(); 

    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(() => 
    { 
     _previewTransform.Rotation = _photoCamera.Orientation; 
     _timer.Start(); 
    }); 
} 

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(() => MessageBox.Show(result.Text)); 
    } 
    catch 
    { 
    } 
} 
+0

看到頁面http://jonas.follesoe.no/2011/07/22/qr-code-scanning-on-windows-phone- 75-using-zxlib /用於定義PhotoCameraLuminanceSource –