datatemplate – Metro风格应用程序中的XAML图像质量(插值)
发布时间:2020-12-14 02:45:24 所属栏目:Windows 来源:网络整理
导读:给定以下 Image对象(它位于ListView对象的DataTemplate中): Image Source="{Binding ImgSource}" ImageOpened="img_ImageOpened" / 我怎么能得到一个高质量的双三次插值图像? (在屏幕上,此图像的大小小于源PNG,但默认大小调整似乎是使用质量差的“最近邻居
给定以下
Image对象(它位于ListView对象的DataTemplate中):
<Image Source="{Binding ImgSource}" ImageOpened="img_ImageOpened" /> 我怎么能得到一个高质量的双三次插值图像? (在屏幕上,此图像的大小小于源PNG,但默认大小调整似乎是使用质量差的“最近邻居”插值执行的). 由于我想单独依赖数据绑定(每当关联数据项的ImgSource发生变化时,图像内容应该更改),我试图设置一个ImageOpened处理程序并将刚刚加载的图像更改为质量更好的图像. 不幸的是,下面的代码似乎不起作用(我只是得到空图像): async void LoadImage(Image imgControl,string source) { try { StorageFile file = await StorageFile.GetFileFromPathAsync(source); IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read); BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream); InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream(); BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync(ras,decoder); enc.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Cubic; enc.BitmapTransform.ScaledHeight = Convert.ToUInt32(imgControl.ActualHeight); enc.BitmapTransform.ScaledWidth = Convert.ToUInt32(imgControl.ActualWidth); await enc.FlushAsync(); Windows.UI.Xaml.Media.Imaging.BitmapImage bImg = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); bImg.SetSource(ras); imgControl.Source = bImg; } catch (Exception e) { return; } } void img_ImageOpened(object sender,RoutedEventArgs e) { Image imgControl = (Image)sender; LoadImage(imgControl,<path to PNG file>); } 解决方法
我在WinRT应用程序中遇到了相同的图像质量问题,并尝试使用RenderOptions.BitmapScalingMode,但它在.NET for Windows Store中不存在(以及System.Windows.Media命名空间).所以我尝试了你的第一个解决方案并修复它以便工作.你是成功的一小步,只需要添加
ras.Seek(0); 允许从头开始读取流. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 汇编 – 如何在DOS中以不同颜色编写文本?
- windows-server-2008-r2 – Windows 2008 R2 gpupdate锁定我
- Flink Time 与 Window
- winapi – win32 – 如何在文本字符串周围绘制一个矩形?
- haskell – 仅从全屏浮动窗口中移除边框(XMonad配置)
- 窗口 – 使用具有多个文件类型的forfile用于搜索掩码?
- Windows环境下使用pip install安装lxml库
- windows-runtime – 将图像添加到MapControl的高效/正确方法
- Windows Phone – 在实际设备上测试Windows Phone 8应用程序
- 记录一下我的windows上的phpstorm中的thinkphp5与xdebugger