5

का उपयोग करें मैं एक विंडोज यूनिवर्सल एप्लिकेशन बना रहा हूं। मैं उपयोगकर्ता को एक तस्वीर अपलोड करने में सक्षम होना चाहता हूं और उपयोगकर्ता को स्पॉट पर एक लेने और उसे भेजने का विकल्प होना चाहिए। मेरे पास MediaCapture एपीआई का उपयोग कर काम कर रहा है। हालांकि मैं केवल एक कैमरा का उपयोग कर सकता हूं, उदाहरण के लिए यदि मेरे फोन में फ्रंट और बैक कैमरा है तो केवल फ्रंट कैमरा का उपयोग किया जाता है। मैं उपयोग में आने वाले कैमरे को कैसे स्विच कर पाऊंगा?विंडोज (फोन) 8.1 कैमरा

मैंने कहीं कुछ इस तरह का उपयोग कर के बारे में कुछ पढ़ा था:

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

हालांकि यह हमेशा मेरे लिए अशक्त देता है, DeviceID हमेशा रिक्त है के बाद से।

वैकल्पिक रूप से वहां एक एप्लिकेशन को नियंत्रण देने का विकल्प है जो तस्वीर लेता है और मेरे आवेदन में ली गई तस्वीर लौटाता है? मैं निम्नलिखित पाया है, लेकिन यह विंडोज यूनिवर्सल क्षुधा के लिए काम नहीं करता: http://msdn.microsoft.com/en-us/library/windows/apps/hh394006(v=vs.105).aspx

+0

क्या आप डीबग मोड में लाइन को चलाने की कोशिश कर सकते हैं: 'var devices = (DeviceInformation.FindAllAsync (DeviceClass.All) का इंतजार करें)। ToList(); ', फिर जांचें कि कौन से डिवाइस लौटाए गए हैं? क्या आप वहां कैमरे पा सकते हैं? – Romasz

उत्तर

4

यहाँ कैसे मैं यह कर देगी:

पहले प्रारंभ हिस्सा

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

दूसरे तस्वीर लेने

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

आपकी समस्या का समाधान करना चाहिए।

संबंधित मुद्दे