我正在使用 PhotoCaptureDevice 类,我可以捕获相机帧,但是当我将 CameraCaptureSequence 的 CameraCaptureFrame.CaptureSequence 中的图像数据复制到 MemoryStream 中然后将其保存在相机胶卷中时出现错误。这是我正在尝试做的代码片段。
PhotoCaptureDevice cam;
cam = await PhotoCaptureDevice.OpenAsync(<front/rear depending on user input>,<resolution depends on user input>);
CameraCaptureSequence seq;
seq = cam.CreateCaptureSequence(1);
cam.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, true);
MemoryStream captureStream1 = new MemoryStream();
seq.Frames[0].CaptureStream = captureStream1.AsOutputStream();//This stream is for saving the image data to camera roll
await cam.PrepareCaptureSequenceAsync(seq);
await seq.StartCaptureAsync();
bool a = seq.Frames[0].CaptureStream.Equals(0);//This value is false during debugging
if(capturestream1.Length>0)//This condition evaluates to false
{
MediaLibrary library = new MediaLibrary();
Picture picture1 = library.SavePictureToCameraRoll("image1", captureStream1);
}
else
{
//Logic to handle condition
}
正如我在评论中添加的那样,该变量的bool a
计算结果为 false,我通过调试代码进行了检查。但由于某种原因,该capturestream1.Length
属性为 0。