[英]How to resize a BitmapImage from another BitmapImage in memory and not on filesystem
This is the continuation of 这是延续
Datacontract serialization/serialization with images
数据合同与图像的序列化/序列化
so now I have a BitmapImage coming from a stream. 所以现在我有一个来自流的BitmapImage。 In short a BitmapImage I want to resize it to a desired size.
简而言之,我想将BitmapImage调整为所需的大小。
I have found tons of code on how to resize from an image on file system but none on how to resize from an already existing BitmapImage 我发现了大量关于如何从文件系统上的图像调整大小的代码,却没有关于如何从已经存在的BitmapImage调整大小的代码
You may use a TransformedBitmap
with an appropriate ScaleTransform
: 您可以将
TransformedBitmap
与适当的ScaleTransform
:
BitmapImage sourceBitmap = ...
var targetBitmap = new TransformedBitmap(sourceBitmap, new ScaleTransform(0.5, 0.5));
The result is a TransformedBitmap, not a BitmapImage. 结果是一个TransformedBitmap,而不是BitmapImage。 However, this shouldn't matter, because in your application there should be no need to deal only with BitmapImages.
但是,这无关紧要,因为在您的应用程序中,不必只处理BitmapImages。 It should be sufficient to do all image-related stuff with the base classes
BitmapSource
or even ImageSource
. 使用基类
BitmapSource
或ImageSource
进行所有与图像有关的工作就足够了。 Eg the Source
property of the Image control is of type ImageSource
. 例如,Image控件的
Source
属性的类型为ImageSource
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.