This is the continuation of
so now I have a BitmapImage coming from a stream. In short a BitmapImage I want to resize it to a desired size.
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
You may use a TransformedBitmap
with an appropriate ScaleTransform
:
BitmapImage sourceBitmap = ...
var targetBitmap = new TransformedBitmap(sourceBitmap, new ScaleTransform(0.5, 0.5));
The result is a TransformedBitmap, not a BitmapImage. However, this shouldn't matter, because in your application there should be no need to deal only with BitmapImages. It should be sufficient to do all image-related stuff with the base classes BitmapSource
or even ImageSource
. Eg the Source
property of the Image control is of type ImageSource
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.