简体   繁体   中英

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. 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

EDIT: 在此处输入图片说明

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM