5

Bir Windows Universal uygulaması oluşturuyorum. Kullanıcının bir fotoğraf yükleyebilmesini istiyorum ve kullanıcının o noktada bir tane alma ve gönderme seçeneği olmalıdır. MediaCapture API'yı kullanarak çalışıyorum. Ancak sadece bir kamera kullanabiliyorum, örneğin telefonumun ön ve arka kamerası varsa, sadece ön kamera kullanılır. Kullanılan kamerayı nasıl değiştirebilirim?Windows (Phone) 8.1 Fotoğraf Makinesi Kullanımı

yere böyle bir şey kullanma hakkında bir şeyler okumuştu: DeviceID hep boş olduğundan

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; 
} 

Ancak bu her zaman benim için null döndürür.

Alternatif olarak, fotoğrafı çeken ve çekilen resmi uygulamaya döndüren bir uygulamaya denetim sağlama seçeneği var mı? Ben aşağıdaki bulduk, ancak Windows Evrensel uygulamalar için çalışmaz: İşte http://msdn.microsoft.com/en-us/library/windows/apps/hh394006(v=vs.105).aspx

+0

Hata ayıklama modunda çalışmayı deneyebilir misin: "var devices = (DeviceInformation.FindAllAsync (DeviceClass.All) bekliyor)) ToList();', sonra hangi aygıtların döndüğünü kontrol edin? Kameraları orada bulabilir misin? – Romasz

cevap

4

bunu yapmak görecektir:

İlk başlatma bölümü

// 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(); 

İkincisi resim çekmek

//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); 

Sorununuzu çözmeniz gerekir.

İlgili konular