我正在试图弄清楚如何从Windows窗体调用Windows相机UI。
我这样做了它确实编译了:
Public Function ShootPicture() As StorageFile
Dim captureUI As New CameraCaptureUI
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg
captureUI.PhotoSettings.AllowCropping = False
Dim GetPhotoTask As Task(Of StorageFile) = captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo)
GetPhotoTask.Wait() ' Blocks current thread until CaptureFileAsync task completes'
Dim result As StorageFile = GetPhotoTask.Result
Return result
End Function
但是.capturefileAsync()上存在'System.InvalidCastException'执行错误:类型'System._ComObject'不能被转换为'System.threading.tasks.task'
有人会对如何解决这个问题有任何想法吗?感谢
如果它可以帮到这里是c#代码翻译:
public StorageFile ShootPicture()
{
CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
captureUI.PhotoSettings.AllowCropping = false;
Task<StorageFile> GetPhotoTask = captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
GetPhotoTask.Wait();
// Blocks current thread until CaptureFileAsync task completes
StorageFile result = GetPhotoTask.Result;
return result;
}
答案 0 :(得分:1)
CaptureFileAsync返回IAsyncOperation,因此请尝试使用await而不是任务:
Dim result As StorageFile = Await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo)