0

我使用适用于 Windows 10 的应用程序。我尝试制作一个用于图像编辑的应用程序。

var client = new HttpClient();
var stream = await client.GetStreamAsync(ImageUrl);
var source = new StreamImageSource(stream);
var info = await source.GetInfoAsync();

我得到一个错误var source = new StreamImageSource(stream);

抛出异常:Lumia.Imaging.Managed.dll 中的“System.IO.FileNotFoundException”

抛出异常:mscorlib.ni.dll 中的“System.IO.FileNotFoundException”

RenderImage 错误:找不到指定的模块。(来自 HRESULT 的异常:0x8007007E)

我究竟做错了什么?我使用 LumiaImagingSDK.UWP 3.0。

4

2 回答 2

0

Imaging SDK 的 StreamImageSource ctor 支持的格式有:Jpeg Png Gif Bmp Wbmp Tiff

检查您的 URL 是否正确并指向其中一种图像格式。

于 2016-05-16T13:23:35.003 回答
0

正如我们在评论中讨论的那样,您想要模糊图像,并且 LumiaImagingSDK.UWP 3.0 中内置了BlurEffect 类,我在这里使用此效果编写了一个演示:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="500" />
        <RowDefinition Height="50" />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Image x:Name="originalimg" Grid.Column="0" />
        <SwapChainPanel x:Name="SwapChainPanelTarget" Grid.Column="1" />
    </Grid>
    <Button Content="Click Me" Click="Button_Click" Grid.Row="1" HorizontalAlignment="Center" />
</Grid>

后面的代码:

private async void Button_Click(object sender, RoutedEventArgs e)
{
    Uri uri = new Uri("xxxx(uri address)");
    using (HttpClient client = new HttpClient())
    {
        try
        {
            HttpResponseMessage response = await client.GetAsync(uri);
            if (response != null && response.StatusCode == HttpStatusCode.Ok)
            {
                string filename = "test.jpg";
                var imageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
                using (IRandomAccessStream stream = await imageFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await response.Content.WriteToStreamAsync(stream);
                }
                StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(filename);

                //show original image in the Image control
                IRandomAccessStream inputStream1 = await file.OpenReadAsync();
                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(inputStream1);
                originalimg.Source = bitmap;

                //use the blureffect
                IRandomAccessStream inputStream = await file.OpenReadAsync();
                BlurEffect blureffect = new BlurEffect();
                inputStream.Seek(0);
                blureffect.Source = new Lumia.Imaging.RandomAccessStreamImageSource(inputStream);
                var render = new SwapChainPanelRenderer(blureffect, SwapChainPanelTarget);
                await render.RenderAsync();
            }
        }
        catch
        {
        }
    }
}

我每次都将图像存储在本地文件夹中,并且使用Windows.Web.Http 命名空间,而不是System.Net.Http 命名空间。由于我无法重现您的问题,因此可以将图像保存到文件并在此处读取文件流。

于 2016-05-17T08:44:55.380 回答