使用Win RT从相机捕获快照

Capturing Snap from Camera using Win RT

本文关键字:快照 相机 Win RT 使用      更新时间:2023-10-16

我正在编写从相机捕获图像的代码。下面是我写的代码。这里方法CapturePhotoToStorageFileAsync没有返回。

auto MediaCap = ref new Windows::Media::Capture::MediaCapture();
auto ImageProp = ref new Windows::Media::Capture::ImageEncodingProperties ();
ImageProp->Height   = 240;
ImageProp->Width    = 320;
ImageProp->Subtype  = "JPEG";

Windows::Storage::StorageFile^ strFile;
auto res = MediaCap->CapturePhotoToStorageFileAsync(ImageProp,strFile);
res->Completed = ref new AsyncActionCompletedHandler([](IAsyncAction ^action)
{
    //action->GetResults();
    //action->Start();
    ///action->Close();
});
res->Start();

我在这里错过了什么吗?

您是想向用户显示UI还是只是默默地捕获?我发现的唯一的c++相机示例使用CameraCaptureUI和CaptureFileAsync -然后操作是获得一个StorageFile^ back。

如果你故意使用CapturePhotoToStorageFileAsync,检查你的功能。

问题已解决

添加了 的代码
  1. InitializeAsync ()
  2. 创建用于存储图像的文件使用

Windows::Storage::StorageFileRetrievalOperation^ CreateFileOp = Windows::Storage::KnownFolders::图片库->CreateFileAsync("Test.jpg");

我找到了Java脚本文章,并在c++中实现。http://code.msdn.microsoft.com/windowsdesktop/Media-Capture-Sample-adf87622/sourcecode?fileId=43837& pathId = 1754477665