2016-09-01 3 views
1

Ich versuche, die Kamera in einer Windows 10 Mobile App zu verwenden, aber ein Fehler tritt auf, wenn ich das Bild mache und versuche, es auf dem Bildschirm zu zeigen.Windows 10 mobile Kamera

Hier ist der Code:

CameraCaptureUI captureUI = new CameraCaptureUI(); 
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; 
captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200); 

StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo); 

if (photo == null) 
{ 
    // User cancelled photo capture 
    return; 
} 

StorageFolder destinationFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("ProfilePhotoFolder", CreationCollisionOption.OpenIfExists); 

await photo.CopyAsync(destinationFolder, "ProfilePhoto.jpg", NameCollisionOption.ReplaceExisting); 
await photo.DeleteAsync(); 

IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read); 
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); 
SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync(); 

SoftwareBitmap softwareBitmapBGR8 = SoftwareBitmap.Convert(softwareBitmap, 
BitmapPixelFormat.Bgra8, 
BitmapAlphaMode.Premultiplied); 

SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource(); 
await bitmapSource.SetBitmapAsync(softwareBitmapBGR8); 

imageControl.Source = bitmapSource; 

Die Meldung Ausnahme:

Eine Ausnahme vom Typ 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll aufgetreten war aber nicht behandelt im Benutzercode

Weitere Informationen: Das System kann die angegebene Datei nicht finden. (Ausnahme von HRESULT: 0x80070002)

Wenn es einen Handler für diese Ausnahme ist, kann das Programm sicher fortgesetzt werden „

Jemand mir helfen kann mit diesem

+1

Haben Sie das Problem gelöst? –

+0

Ja, hat es getan. Vielen Dank! –

Antwort

1

Dies liegt daran, Sie.? die photo gelöscht, aber dann versucht, die photo zu lesen, die gerade gelöscht, so dass die Ausnahme „FileNotFound“ werfen wird. Bitte entfernen sie die folgende Codezeile wird es funktionieren.

await photo.DeleteAsync(); 

Aber ich denke, was Sie wirklich tun möchten, ist das Foto zu löschen, das von CameraCaptureUI erhalten wird, und lesen Sie dann das Foto aus dem lokalen Ordner, der bereits kopiert wurde. In diesem Fall sollte der Code wie folgt lauten:

await photo.CopyAsync(destinationFolder, "ProfilePhoto.jpg", NameCollisionOption.ReplaceExisting); 
await photo.DeleteAsync(); 
StorageFile newphoto = await destinationFolder.GetFileAsync("ProfilePhoto.jpg"); 
IRandomAccessStream stream = await newphoto.OpenAsync(FileAccessMode.Read); 
Verwandte Themen