我使用TransformedBitmap
类使用TransformedBitmap.CopyPixels
将缩放图像绘制到Bitmap
。有没有办法指定使用的缩放模式? RenderOptions.SetBitmapScalingMode
似乎没有影响任何东西。我想使用最近的邻居,但它似乎使用某种双线性滤波器。TransformedBitmap缩放模式
2
A
回答
3
- 不可能指定缩放算法,它是通过设计。
- RenderOptions.SetBitmapScalingMode仅适用于渲染,例如,你有一个32 * 32的图标,并希望在256 * 256,但仍处于块状方式(近邻)
更新,以显示它
你是怎么克服这个问题的一些方法:
自己做这件事: 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继承的,很可能根本不会改变现有的代码。
0
public static class Extensions
{
public static BitmapFrame Resize(this
BitmapSource photo, int width, int height,
BitmapScalingMode scalingMode)
{
var group = new DrawingGroup();
RenderOptions.SetBitmapScalingMode(
group, scalingMode);
group.Children.Add(
new ImageDrawing(photo,
new Rect(0, 0, width, height)));
var targetVisual = new DrawingVisual();
var targetContext = targetVisual.RenderOpen();
targetContext.DrawDrawing(group);
var target = new RenderTargetBitmap(
width, height, 96, 96, PixelFormats.Default);
targetContext.Close();
target.Render(targetVisual);
var targetFrame = BitmapFrame.Create(target);
return targetFrame;
}
}
从http://weblogs.asp.net/bleroy/resizing-images-from-the-server-using-wpf-wic-instead-of-gdi
相关问题
- 1. TransformedBitmap BitmapImage
- 2. HTML5视频缩放模式?
- 3. 阶段缩放模式错误#1009
- 4. 在横向模式下不缩放?
- 5. 通过MVVM模式缩放图形?
- 6. 水平缩放和设计模式
- 7. 的MPMoviePlayerController缩放模式问题
- 8. 在肖像模式下关闭缩放
- 9. 缩放Aframe模型
- 10. 的MPMoviePlayerController缩放模式是不是在iPad景观模式
- 11. 以模板方式在ARM模式下自动缩放IaaS VM
- 12. TransformedBitmap对象的'Stride'困境
- 13. Android的媒体播放器集视频缩放模式
- 14. 是否可以在Xcode6中模拟iphone6 +的缩放模式?
- 15. 在缩放模式下出现模糊的文字UITextField/TextView
- 16. 缩放CALayer模糊视图
- 17. 缩放跟随模型
- 18. 缩放文本模糊
- 19. 避免缩放规模
- 20. Sketchup API和缩放模型
- 21. 缩放和缩放
- 22. Flot缩放模式没有以编程方式更新
- 23. 在VirtualBox中退出缩放模式的快捷方式?
- 24. OpenLayers缩放样式GoogleMaps
- 25. QScrollBar样式缩放柄
- 26. 以脚本形式播放缩放
- 27. 开放式缩放自动化
- 28. Java模式缩进
- 29. 使用Javascript缩放/缩放多个图像的最佳方式?
- 30. GLSurfaceView缩放(PINCH缩放)
有趣拿了,你有一个替代有什么建议? (鉴于我有一个bitmapsource需要缩放和复制到位图) – phosphoer 2013-04-05 18:40:10
我已经在我的答案中添加了几种方法给你。 (抱歉,但我在我的手机上,这不是很实际) – Aybe 2013-04-05 23:42:33
我已经更新了我的答案。 – Aybe 2013-04-09 17:14:27