简体   繁体   English

使用Silverlight进行图像重新缩放(缩小尺寸)

[英]Image rescale (downsize) with Silverlight

I have an array of graphs, that are 2000x1000 pixels pngs. 我有一组图形,即2000x1000像素的png。 When I put them into a silverlight Image that auto-sized with the browser window, DisplayImage.Source = new BitmapImage(GetHeatmapURL()); 当我把它们放入一个自动调整大小的Silverlight图像时, DisplayImage.Source = new BitmapImage(GetHeatmapURL()); they images look distorted and for some browser sizes much worse than for some others. 它们的图像看起来很扭曲,而且某些浏览器的尺寸比其他浏览器大得多。

I want to fiddle with some setting that would improve the quality of this downsampling, is this possible? 我想摆弄一些可以改善这种下采样质量的设置,这可能吗? Am I doing something wrong? 难道我做错了什么? My first approach was to put the Image into a Viewbox. 我的第一种方法是将图像放入视图框。 That looked even worse. 这看起来更糟糕。 Googling gives virtually nothing useful... 谷歌搜索几乎没有任何用处......

Any help much appreciated. 任何帮助非常感谢。

PS. PS。 I'm working with Silverlight 4. 我正在使用Silverlight 4。

When making use of the Viewbox you need to make sure to set Stretch to Uniform to respect the original height/width ratio. 使用Viewbox ,需要确保将“ Stretch设置为“ Uniform以遵守原始的高/宽比。

In regards to the rendering of the image at the given aspect ratio and size; 关于以给定的宽高比和尺寸渲染图像; that is contingent on the framework. 这取决于框架。

You could check out the WriteableBitmapEx project on CodePlex which gives you a Resize() extension method for the Silverlight WritableBitmap class where you can use either Bilinear or Nearest Neighbor interpolation. 您可以在CodePlex上查看WriteableBitmapEx项目,该项目为Silverlight WritableBitmap类提供了Resize()扩展方法,您可以在其中使用双线性或最近邻插值。 Resizing with the Bilinear interpolation might give you something that looks better than the ViewBox resizing, but you would have to test it out. 使用双线性插值调整大小可能会给你一些看起来比ViewBox调整大小更好的东西,但你必须测试它。

var resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM