user4367090
user4367090

Reputation:

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: enter image description here

Upvotes: 3

Views: 10767

Answers (1)

Clemens
Clemens

Reputation: 128136

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, which is the type of the Source property of the Image control.

Upvotes: 11

Related Questions