使用 Lumia Imaging SDK 渲染图像时出现异常

Exception When Rendering an Image Using Lumia Imaging SDK

在我的 WP8.1 应用程序中,我尝试使用 Lumia(以前称为诺基亚)成像 SDK 裁剪图像。使用 FileOpenPicker:

检索图像
public async void ContinueFileOpenPicker(Windows.ApplicationModel.Activation.FileOpenPickerContinuationEventArgs args) {
    if (args.Files.Count > 0) {
        _stream = await args.Files[0].OpenAsync(Windows.Storage.FileAccessMode.Read);
        _bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
        await _bitmapImage.SetSourceAsync(_stream);
        SelectedImage.Source = _bitmapImage;
    }
    else {
        Debug.WriteLine("Operation cancelled.");
    }
}

然后在按钮处理程序中应用过滤器(在用户选择裁剪区域之后;尺寸仅用于测试目的):

private async void GetImageAcceptButton_Click(object sender, RoutedEventArgs e) {
    await GetCroppedBitmapAsync();
}

async public Task GetCroppedBitmapAsync() {
    using (var source = new RandomAccessStreamImageSource(_stream)) {
        using (var filterEffect = new FilterEffect(source)) {
            var filter = new CropFilter(new Windows.Foundation.Rect(0, 0, 100, 100));
            filterEffect.Filters = new IFilter[] { filter };
            var target = new WriteableBitmap(50, 50);
            using (var renderer = new WriteableBitmapRenderer(filterEffect, target)) {
                await renderer.RenderAsync();
                SelectedImage.Source = target;
            }
        }
    }
}

RenderAsync()调用抛出异常:

System.Runtime.InteropServices.COMException occurred
HResult=-2147467259
Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
Source=mscorlib
ErrorCode=-2147467259

应用过滤器似乎相当简单。为什么这里失败了?

您应该启用本机调试并查看输出 window。您目前缺少真正的异常消息(它试图更具体)。异常消息字符串 "smuggled" 跨越 WinRT 调用边界,只有一个 HRESULT 被正式传递(这里,E_FAIL)。

顺便说一句,这是 Silverlight 8.1 还是通用应用程序?

我猜答案可能是您需要 seek/rewind 返回流。可能位置在最后。