I’m using JavaScript for Windows 8 Metro App development; however, C# is not out of the question. I am trying to find a way to specify the highest resolution my webcam can support for photo capturing. So far, I’ve been using MediaCapture class so I can have a preview and still capture images. I’ve noticed the CaptureUI supports an option for MaxPhotoResolution. However, I want this to be automatic and not require user interaction. I’m running out of ideas. This is for a kiosk application so workarounds are welcome as I have full control of the device. Any ideas or suggestions?
For testing, I’m using the LifeCam Studio. The camera app picks up 1920×1080 while my application captures photos in 640×480. Also, the software that comes with the drivers works flawlessly! Is this out of my control?
Updates
I’ve been looking into settings specific camera settings; this popped up; however, so far, I haven’t had any luck with it…
Update for September 18
I’ve been digging and have come up with this. Resolution properties are returned; however, the setMediaStreamPropertiesAsync method has no effect! I’m running out of ideas.
Update for December 13
I decided to give this one last try and using some of the method described on the 18th, it worked via JavaScript, with the Lifecam Studio, on the official Windows 8 release. As for why, I don’t know. Here’s the code I used:
//media=MediaCapture object
function setBestResolution(media) {
//Gets collection of objects each describing the resolution, etc.
var resolutions = media.videoDeviceController.getAvailableMediaStreamProperties(Windows.Media.Capture.MediaStreamType.photo);
var numResolutions=resolutions.length;
for (var r = 0; r<resolutions;r++){
var res = resolutions[r];
//.width and .height are props. Debug to see all.
}
//I chose 40 as best option; however, programmatically you can choose any. I have dedicated kiosk app and same webcam and therefore don't need to.
media.videoDeviceController.setMediaStreamPropertiesAsync(Windows.Media.Capture.MediaStreamType.photo, resolutions[40]);
}
I’m a little unclear on what you’re trying to do. Is the issue that you want to capture a specific photo resolution or is it that you want to capture at a particular aspect ratio?
When using the CameraCaptureUI you can use the PhotoSettings property to set the criteria of the captured photo:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.media.capture.cameracaptureui.photosettings.aspx
For example, you can set the CroppedAspectRatio to make sure the image is always 4:3 or 16:9. You can also set the MaxResolution property to limit the pixel dimensions of the photo when it is captured.
The MediaCapture class is only needed when you want to have a custom capture experience as part of your application instead of using the system dialog. The default initialization for MediCapture initializes the device at its highest resolution (I believe, though I haven’t tested). It is possible to override what resolution you want MediaCapture to capture at, but you are limited to the resolutions supported by the device. You can enumerate the resolutions supported by the device and the forum post you linked to shows how:
http://social.msdn.microsoft.com/Forums/en-SG/winappswithcsharp/thread/751b8d83-e646-4ce9-b019-f3c8599e18e0
Of course, the resolutions supported by your device may not be the resolutions or aspect ratio you really want to keep. Therefore you may end up having to present the user with the ability to crop the photo and you may end up having to resize the image further. This will require extra code and extra UI pieces that you would need to build. If you have code to allow the user to crop and if you have code to resize (or downsample) the image to the exact resolution you want, then there isn’t really any need to change the resolution that the MediaCapture device initializes at.
One strategy would be to create a temporary file in ApplicationData.Current.TemporaryFolder and call MediaCapture.CapturePhotoToStreamAsync on that temporary file. Then display that file in your own UI to allow cropping and finally resize it to the resolution you want before saving the final image out to real target folder.
Though you’ll have to create your own UI for allowing the user to select the area of the image they want to keep, the WriteableBitmapEx project on CodePlex will probably prove to be exceptionally helpful in doing the actual cropping and resizing:
http://writeablebitmapex.codeplex.com/