5

Ich erstelle eine Windows Universal-Anwendung. Ich möchte dem Nutzer ein Bild hochladen lassen und der Nutzer sollte die Möglichkeit haben, ein Bild vor Ort zu versenden und zu versenden. Ich arbeite mit der MediaCapture API. Allerdings kann ich scheinbar nur eine Kamera benutzen, also wenn zB mein Handy eine Front- und eine Rückkamera hat wird nur die Frontkamera benutzt. Wie kann ich die verwendete Kamera wechseln?Windows (Telefon) 8.1 Kamera Verwendung

Ich hatte etwas irgendwo gelesen, um so etwas wie dies mit:

private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desired) 
{ 
    DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture)) 
     .FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desired); 

    return deviceID; 
} 

Doch diese gibt immer null für mich, da die deviceID immer null ist.

Gibt es alternativ die Möglichkeit, einer Anwendung, die das Bild aufnimmt und das aufgenommene Bild an meine Anwendung zurückgibt, die Kontrolle zu geben? Ich habe folgendes gefunden, aber es funktioniert nicht für Windows Universal-Apps: http://msdn.microsoft.com/en-us/library/windows/apps/hh394006(v=vs.105).aspx

+0

Können Sie versuchen, im Debug-Modus die Zeile auszuführen: 'var devices = (warten DeviceInformation.FindAllAsync (DeviceClass.All)). ToList();', dann überprüfen, welche Geräte zurückgegeben werden? Kannst du die Kameras dort finden? – Romasz

Antwort

4

Hier ist, wie ich es tun würde:

Zuerst wird die Initialisierung Teil

// First need to find all webcams 
DeviceInformationCollection webcamList = await DeviceInformation.FindAllAsync(DeviceClass.All) 

// Then I do a query to find the front webcam 
DeviceInformation frontWebcam = (from webcam in webcamList 
where webcam.EnclosureLocation != null 
&& webcam.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front 
select webcam).FirstOrDefault(); 

// Same for the back webcam 
DeviceInformation backWebcam = (from webcam in webcamList 
where webcam.EnclosureLocation != null 
&& webcam.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back 
select webcam).FirstOrDefault(); 

// Then you need to initialize your MediaCapture 
newCapture = new MediaCapture(); 
await newCapture.InitializeAsync(new MediaCaptureInitializationSettings 
     { 
      // Choose the webcam you want 
      VideoDeviceId = backWebcam.Id, 
      AudioDeviceId = "", 
      StreamingCaptureMode = StreamingCaptureMode.Video, 
      PhotoCaptureSource = PhotoCaptureSource.VideoPreview 
     }); 

// Set the source of the CaptureElement to your MediaCapture 
// (In my XAML I called the CaptureElement *Capture*) 
Capture.Source = newCapture; 

// Start the preview 
await newCapture.StartPreviewAsync(); 

nehmen Zweitens das Bild

//Set the path of the picture you are going to take 
StorageFolder folder = ApplicationData.Current.LocalFolder; 
var picPath = "\\Pictures\\newPic.jpg"; 

StorageFile captureFile = await folder.CreateFileAsync(picPath, CreationCollisionOption.GenerateUniqueName); 

ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg(); 

//Capture your picture into the given storage file 
await newCapture.CapturePhotoToStorageFileAsync(imageProperties, captureFile); 

Das sollte Ihr Problem lösen.