如果你想減少圖像中的兩個部分,爲什麼不使用CroppedBitmap
類?
請考慮以下XAML。一個來源BitmapImage
由兩個CroppedBitmaps
共享,每個顯示來源的不同部分。
<Window.Resources>
<BitmapImage x:Key="bmp" UriSource="SomeBitmap.jpg" />
</Window.Resources>
<StackPanel>
<Image>
<Image.Source>
<CroppedBitmap Source="{StaticResource ResourceKey=bmp}">
<CroppedBitmap.SourceRect>
<Int32Rect X="0" Y="0" Width="100" Height="100" />
</CroppedBitmap.SourceRect>
</CroppedBitmap>
</Image.Source>
</Image>
<Image>
<Image.Source>
<CroppedBitmap Source="{StaticResource ResourceKey=bmp}">
<CroppedBitmap.SourceRect>
<Int32Rect X="100" Y="150" Width="50" Height="50" />
</CroppedBitmap.SourceRect>
</CroppedBitmap>
</Image.Source>
</Image>
</StackPanel>
更新:做類似的事情在代碼:
var bitmapImage = new BitmapImage(new Uri(...));
var sourceRect = new Int32Rect(10, 10, 50, 50);
var croppedBitmap = new CroppedBitmap(bitmapImage, sourceRect);
至於將影像保存到文件(這是一個單獨的問題,應受到同樣的對待),試圖在尋找它網頁。這裏有一個命中:http://blogs.msdn.com/b/kirillosenkov/archive/2009/10/12/saving-images-bmp-png-etc-in-wpf-silverlight.aspx –
嘗試使用OpenGL。你會發現它比GDI +(System.Drawing)和WPF更快更有用。 OpenTK(www.opentk.com)是.NET圍繞OpenGL的一個很好的包裝。 – IDWMaster