1

在我的 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

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

4

1 回答 1

1

您应该启用本机调试并查看输出窗口。您目前缺少真正的异常消息(试图更具体)。异常消息字符串通过 WinRT 调用边界“走私”,只有 HRESULT 正式通过(此处为 E_FAIL)。

这是 Silverlight 8.1 还是通用应用程序?

我对答案的猜测可能是您需要寻找/倒回流。位置可能在最后。

于 2015-03-11T06:52:50.413 回答