我是 WinRT c++ 的新手。我正在尝试从 C# 传递 StorageFile 图像并打开文件并将其设置为 WinRT 中 BitmapImage 中的源以提取图像的高度和宽度。我正在使用以下代码。
auto openOperation = StorageImageFile->OpenAsync(FileAccessMode::Read); // from http://msdn.microsoft.com/en-us/library/windows/desktop/hh780393%28v=vs.85%29.aspx
openOperation->Completed = ref new
AsyncOperationCompletedHandler<IRandomAccessStream^>(
[=](IAsyncOperation<IRandomAccessStream^> ^operation, AsyncStatus status)
{
auto Imagestream = operation->GetResults();
BitmapImage^ bmp = ref new BitmapImage();
auto bmpOp = bmp->SetSourceAsync(Imagestream);
bmpOp->Completed = ref new
AsyncActionCompletedHandler (
[=](IAsyncAction^ action, AsyncStatus status)
{
action->GetResults();
UINT32 imageWidth = (UINT32)bmp->PixelWidth;
UINT32 imageHeight = (UINT32)bmp->PixelHeight;
});
});
此代码似乎不起作用。在 BitmapImage^ bmp = ref new BitmapImage(); 之后 调试器停止说没有找到源代码。你能帮我写出正确的代码吗?