【发布时间】:2016-01-05 21:04:50
【问题描述】:
我正在使用 windows phone 8.1(RT) 我使用 MediaCapture 拍摄照片(请记住,我对预览要拍摄的照片不感兴趣)。 我使用了以下代码,但图片的质量很糟糕,只有在拍摄的照片中可以看到照亮光线的部分。
private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desiredCamera)
{
// get available devices for capturing pictures
DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredCamera);
if (deviceID != null) return deviceID;
else throw new Exception(string.Format("Camera of type {0} doesn't exist.", desiredCamera));
}
public async Task takeAPicture()
{
var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
captureManager = new MediaCapture();
await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id
});
var maxResolution = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate((i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
await captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxResolution);
StorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("myFirstPhoto.jpg", CreationCollisionOption.GenerateUniqueName);
//take a photo with choosen Encoding
await captureManager.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoFile);
captureManager.Dispose();
}
感谢您的帮助。
【问题讨论】:
-
我在手机上玩过一次,发现最大的宽度并不意味着最大的分辨率。为什么不列举可用的宽度/高度并选择能产生最大乘法结果的组合(宽度*高度)?
标签: c# windows-runtime windows-phone-8.1