This is a migrated thread and some comments may be shown as answers.

convert writeablebitmap to bitmapimage

2 Answers 342 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
HDC
Top achievements
Rank 1
HDC asked on 10 Aug 2011, 05:52 AM
Can the ImageEditor be used to convert a writeablebitmap to a bitmapimage, but without the need to use any sort of graphical interface?

Here is my scenario:

I have a large image (>2MB)
I rescale it to a thumbnail (say 180x180 pixels) so it would consume less memory using a writeablebitmap as output

I now need to convert this writeablebitmap back to a bitmapimage.

Can the imageeditor be of service for this?








2 Answers, 1 is accepted

Sort by
0
Accepted
Kammen
Telerik team
answered on 10 Aug 2011, 11:57 AM
Hi Peter,

You can use RadBitmap to resize your images or pass your WriteableBitmap in the constructor. Then export the RadBitmap with the proper format provider to a stream. Finally, pass this stream to the SetSource method of the BitmapImage you want as a result. Here is a sample code on how to do that.

RadBitmap radImage = new RadBitmap(Source);
  
MemoryStream stream = new MemoryStream();
PngFormatProvider provider = new PngFormatProvider(); // Choose the right FormatProvider.
provider.Export(radImage, stream);
              
BitmapImage bi = new BitmapImage();
bi.SetSource(stream);

Greetings,
Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
HDC
Top achievements
Rank 1
answered on 10 Aug 2011, 12:26 PM
Hi Kammen,

Thank you very much.

This is exactly what i was looking for!

Best Regards,

Peter
Tags
ImageEditor
Asked by
HDC
Top achievements
Rank 1
Answers by
Kammen
Telerik team
HDC
Top achievements
Rank 1
Share this question
or