我使用 TransformedBitmap
类通过 TransformedBitmap.CopyPixels
将缩放图像绘制为 Bitmap
。有没有办法指定使用的缩放模式? RenderOptions.SetBitmapScalingMode
似乎没有任何影响。我想使用最近邻,但它似乎使用某种双线性滤波器。
最佳答案
- 无法指定缩放算法,这是设计使然。
- RenderOptions.SetBitmapScalingMode 仅适用于渲染,例如您有一个 32*32 的图标,并希望以 256*256 的分辨率显示它,但仍然以 block 状方式显示(最近邻居)
更新
克服此问题的几种方法:
自己做: http://tech-algorithm.com/articles/nearest-neighbor-image-scaling/
使用表格: https://stackoverflow.com/a/1856362/361899
自定义绘图: How to specify the image scaling algorithm used by a WPF Image?
还有 AForge,但这可能无法满足您的需求。
更新2
WriteableBitmapEx 可能会轻松为您完成这项工作:http://writeablebitmapex.codeplex.com/
您可以调整 WriteableBitmap 的大小、指定插值模式以及最近邻。
TransformedBitmap 和 WriteableBitmapEx 都继承自 BitmapSource,可能您无需对现有代码进行任何更改。
关于c# - TransformedBitmap 缩放模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15821358/