[英]How to set maximum resolution with MediaCapture in windows phone 8.1?
我在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();
}
謝謝您的幫助。
好像您配置MediaCapture來給您“預覽質量”的照片一樣。 改為這樣做:
await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.Photo, // I believe your bug was here
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id
});
或者說真的,只需為大多數這些屬性嘗試默認設置,然后僅將VideoDeviceId設置為選擇攝像機即可。 它應該有助於縮小問題的范圍。
至於設置更高的照片拍攝分辨率,則可能需要執行以下操作:
private async Task SetPhotoResolution()
{
var resolutions = _captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Select(x => x as VideoEncodingProperties);
var maxRes = resolutions.OrderByDescending(x => x.Height * x.Width).FirstOrDefault();
await _captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxRes);
}
請確保照片分辨率的縱橫比與預覽分辨率的縱橫比匹配,否則在某些手機的邊緣附近可能會出現一些條紋。
另外,我在此電話上測試過的電話僅針對MediaStreamType.Photo
流上的GetAvailableMediaStreamProperties
調用返回了NV12 VideoEncodingProperties
。 您可能需要在其他設備上處理還包含ImageEncodingProperties的枚舉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.