我试图用我的Lumia 930 Windows Phone拍摄照片2天。
我使用以下代码:
public sealed partial class MainPage : Page
{
Windows.Media.Capture.MediaCapture captureManager;
public MainPage()
{
this.InitializeComponent();
First.Click += async (sender, e) => await Initialize();
Second.Click += async (sender, e) => await shutter();
}
private async Task Initialize()
{
captureManager = new MediaCapture();
var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
List<Windows.Devices.Enumeration.DeviceInformation> _deviceList = new List<Windows.Devices.Enumeration.DeviceInformation>();
for (var i = 0; i < devices.Count; i++)
{
_deviceList.Add(devices[i]);
}
MediaCaptureInitializationSettings _captureInitSettings = null;
_captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
_captureInitSettings.AudioDeviceId = "";
_captureInitSettings.VideoDeviceId = "";
_captureInitSettings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.AudioAndVideo;
_captureInitSettings.PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.Photo;
if (_deviceList.Count > 0)
_captureInitSettings.VideoDeviceId = _deviceList[0].Id;
await captureManager.InitializeAsync(_captureInitSettings);
//capturePreview.Source = captureManager;
//await captureManager.StartPreviewAsync();
await SetResolution();
}
public async Task SetResolution()
{
System.Collections.Generic.IReadOnlyList<IMediaEncodingProperties> res;
res = this.captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
uint maxResolution = 0;
int indexMaxResolution = 0;
string s = "";
if (res.Count >= 1)
{
for (int i = 0; i < res.Count; i++)
{
VideoEncodingProperties vp = (VideoEncodingProperties)res[i];
var frameRate = (vp.FrameRate.Numerator / vp.FrameRate.Denominator);
s = i + ") " + vp.Subtype + ", ";
s = s + vp.Width;
s = s + " x " + vp.Height;
s = s + " , Frame/s: " + frameRate;
if (vp.Width > maxResolution && vp.Subtype.Equals("YUY2"))
{
indexMaxResolution = i;
maxResolution = vp.Width;
}
if (true)
{
Debug.WriteLine(s);
}
s = "";
}
//setting resolution
await captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, res[indexMaxResolution]);
return;
}
}
private async Task shutter()
{
ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
var photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync("Photo.JPG", Windows.Storage.CreationCollisionOption.GenerateUniqueName);
await captureManager.CapturePhotoToStorageFileAsync(imageProperties, photoStorageFile);
return;
}
}
您可以在此处找到解决方案:
当我选择
时
_captureInitSettings.PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview;
我得到了一张照片,但其分辨率/质量非常糟糕。当使用Photo时,更有意义的是,我得到一个2MB的文件,这听起来很正确,但内容只有黑色和黄色线,就像镜头关闭一样。
相机肯定在使用诺基亚相机或其他应用程序,因此它不会成为硬件问题。
答案 0 :(得分:1)
我认为您没有为您的任务选择合适的API。
您应该使用CameraCaptureTask(如果您想要保存在库中的标准相机UI +图像)或PhotoCamera(如果您想要自己的相机UI和/或者您不希望将照片保存在用户的库中。
不要忘记清单中的ID_CAP_ISV_CAMERA功能。
答案 1 :(得分:0)
我现在设法通过首先开始预览拍摄照片。没有预览似乎无法工作:/