2016-10-08 3 views
-3

UWP 프로젝트에서 ZXing을 사용하려고하는데 많은 튜토리얼을 읽었습니다. 마지막 자습서에서는 WritableBitmap을 사용해야한다고 말했습니다. 'cos 비트 맵은 UWP에서 사용할 수 없습니다.바코드 디코딩을 위해 'WriteableBitmap'을 UWP의 'LuminanceSource'로 변환 할 수 없습니다.

그러나이

유형을 변환 할 수 없습니다

나에게 말한다 'Windows.UI.Xaml.Media.Imaging.WriteableBitmap' 에 'ZXing.LuminanceSource'

public class QrCodeHelpers 
{ 
    public static void ReadQrCodeFromBitmap(WriteableBitmap image) 
    { 
     IBarcodeReader reader = new BarcodeReader(); 
     var generic = new BarcodeReaderGeneric<WriteableBitmap>(); 

     // detect and decode the barcode inside the bitmap 
     var result = reader.Decode((ZXing.LuminanceSource)image); 
     // do something with the result 
    } 
} 

어떻게 할 수 이 일하게? MediaCapture의 이미지가 있으며이를 사용하여 QR 코드의 데이터를 얻을 수 있습니다. 어떤 해결책?

+1

당신은 그런 식으로 캐스팅 할 수 없습니다. – ChrisF

+0

네, 작동하지 않을 거란 건 알지만 그건 내 문제입니다. 이것은 받아 들인 대답입니다 : http://stackoverflow.com/questions/20650509/barcode-scanner-for-metro-apps 그것은 동일한 것을 사용합니다 ... – tixovoxi

+0

@tixovoxi, 링크 된 질문에 codeplex 예제 링크가 있습니다. 미디어 요소. 이 예제의 어떤 것도 LuminanceSource와 아무런 관련이 없습니다. – Nkosi

답변

0

우선 Peter Duniho에 동의합니다.

그런 다음 reader.Decode() 메서드를 사용하려는 경우 매개 변수는 실제로 SoftwareBitmapLuminanceSource입니다.

처음에는 WriteableBitmapSoftwareBitmap으로 변환 한 다음 SoftwareBitmapLuminanceSource으로 변환 할 수 있습니다. 그리고 코드 IBarcodeReader reader = new BarcodeReader();에 오타가 있습니까? IBarcodeReader은 인터페이스입니다.

어떤 방법, 당신은 다음과 같은 예를 들어 코딩 할 수 있습니다 : 하나의 객체가 다른 서브 클래스가 아닌 경우

SoftwareBitmap sbmp = SoftwareBitmap.CreateCopyFromBuffer(wbmp.PixelBuffer, 
    BitmapPixelFormat.Bgra8, 
    wbmp.PixelWidth, 
    wbmp.PixelHeight); //converter WriteableBitmap to SoftwareBitmap, wbmp represents the WriteableBitmap 


//convert SoftwareBitmap to SoftwareBitmapLuminanceSource 
SoftwareBitmapLuminanceSource luminanceSource = new SoftwareBitmapLuminanceSource(sbmp); 

BarcodeReader reader = new BarcodeReader(); //change IBarcodeReader to BarcodeReader 
var generic = new BarcodeReaderGeneric<WriteableBitmap>(); //This code for what? 
var result = reader.Decode(luminanceSource); 
관련 문제