![](/img/trans.png)
[英]WPF: How to create a BitmapImage… from another BitmapImage?
[英]How to resize a BitmapImage from another BitmapImage in memory and not on filesystem
這是延續
所以現在我有一個來自流的BitmapImage。 簡而言之,我想將BitmapImage調整為所需的大小。
我發現了大量關於如何從文件系統上的圖像調整大小的代碼,卻沒有關於如何從已經存在的BitmapImage調整大小的代碼
您可以將TransformedBitmap
與適當的ScaleTransform
:
BitmapImage sourceBitmap = ...
var targetBitmap = new TransformedBitmap(sourceBitmap, new ScaleTransform(0.5, 0.5));
結果是一個TransformedBitmap,而不是BitmapImage。 但是,這無關緊要,因為在您的應用程序中,不必只處理BitmapImages。 使用基類BitmapSource
或ImageSource
進行所有與圖像有關的工作就足夠了。 例如,Image控件的Source
屬性的類型為ImageSource
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.