2012-08-27 54 views
1

我在WPF中有一個圖像控件。我需要減小圖像尺寸控制的寬度和高度。但是當我這樣做時,圖像看起來不太好。數據丟失更多。減少WPF圖像控件中的圖像分辨率

所以我想,以減少圖像的分辨率,而不是僅僅改變圖像控制寬度和高度。

任何一個可以幫助我如何改變在WPF圖像控件綁定的圖像的圖像分辨率

[我的意思是像已經被綁定到圖像控制現在我要改變的分辨率只有]

回答

0

1)嘗試一個ViewBox:把你的圖像放在ViewBox中。
2)由於像素對齊問題,有時渲染引擎會失去質量,特別是在低分辨率設備上。查看SnapsToDevicePixels屬性,並嘗試在ViewBox的包含控件AND/OR中將其設置爲true。
3)顯然,你可以編寫一個控制來執行分辨率更改,但這是一些工作。

0

可以使用DecodePixelWidth屬性是這樣的:

<Image Stretch="Fill"> 
    <Image.Source> 
     <BitmapImage CacheOption="OnLoad" DecodePixelWidth="2500" UriSource="Images/image.jpg"/> 
    </Image.Source> 
</Image> 
4

在.NET 4中,他們改變了默認的圖像縮放爲低品質的一個......所以你可以用BitmapScalingMode切換回更高質量之一:

<Image RenderOptions.BitmapScalingMode="HighQuality" 
     Source="myimage.png" 
     Width="100" 
     Height="100" /> 

如果您的源圖像是一個巨大的圖像(這隻會減少應用程序中的內存使用量),您還可以將上述內容與解碼選項等其他選項結合使用。

其他選項,以防止 「blurryness」 是把UseLayoutRounding="True"您的根元素(即窗口)上....我們建議在.NET 4中,而不是SnapToDevicePixels使用此:

+0

我的GIF圖像的大小是相當巨大的。如何使用WPF Animated GIF設置'DecodePixelWidth'和'DecodePixelHeight'? – Casper

+0

關於我的問題的更多細節:https://stackoverflow.com/q/45768644/2828227 – Casper

0

試試這個。

Image img = new Image(); 

var buffer = System.IO.File.ReadAllBytes(_filePath); 
MemoryStream ms = new MemoryStream(buffer); 

BitmapImage src = new BitmapImage(); 
src.BeginInit(); 
src.StreamSource = ms; 
src.DecodePixelHeight = 200;//Your wanted image height 
src.DecodePixelWidth = 300; //Your wanted image width 
src.EndInit(); 

img.Source = src;