正如我们在评论中讨论的那样,您想要模糊图像,并且 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 命名空间。由于我无法重现您的问题,因此可以将图像保存到文件并在此处读取文件流。