convert writeablebitmap to bitmapimage

3 posts, 1 answers
  1. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 10 Aug 2011 Link to this post

    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. Answer
    Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 10 Aug 2011 Link to this post

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

  3. DevCraft banner
  4. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 10 Aug 2011 Link to this post

    Hi Kammen,

    Thank you very much.

    This is exactly what i was looking for!

    Best Regards,

    Peter
Back to Top