我使用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. 在橫向模式下不縮放?
- 4. 在肖像模式下關閉縮放
- 5. 縮放Aframe模型
- 6. 以模板方式在ARM模式下自動縮放IaaS VM
- 7. TransformedBitmap對象的'Stride'困境
- 8. Android的媒體播放器集視頻縮放模式
- 9. 縮放文本模糊
- 10. 縮放跟隨模型
- 11. 是否可以在Xcode6中模擬iphone6 +的縮放模式?
- 12. 在縮放模式下出現模糊的文字UITextField/TextView
- 13. 縮放和縮放
- 14. Flot縮放模式沒有以編程方式更新
- 15. OpenLayers縮放樣式GoogleMaps
- 16. QScrollBar樣式縮放柄
- 17. 以腳本形式播放縮放
- 18. 開放式縮放自動化
- 19. Java模式縮進
- 20. 使用Javascript縮放/縮放多個圖像的最佳方式?
- 21. Gmaps4rails:縮放(不縮放)gmap
- 22. GLSurfaceView縮放(PINCH縮放)
- 23. 在縮放模式期間在UIScrollVIew上添加UIView
- 24. 在MATLAB縮放模式下收聽按鍵
- 25. Flot不會在時間模式下使用xaxis縮放
- 26. 如何讓Chrome在Xmonad的全屏模式下正確縮放
- 27. SVG:模式中的非縮放筆畫不起作用?
- 28. jquery定製旋轉木馬內圖像縮放模式
- 29. 如何在雙頁模式下實現可縮放的UIPageViewController?
- 30. 如何將圖像縮放到全屏模式?
有趣拿了,你有一個替代有什麼建議? (鑑於我有一個bitmapsource需要縮放和複製到位圖) – phosphoer 2013-04-05 18:40:10
我已經在我的答案中添加了幾種方法給你。 (抱歉,但我在我的手機上,這不是很實際) – Aybe 2013-04-05 23:42:33
我已經更新了我的答案。 – Aybe 2013-04-09 17:14:27