In Silverlight, how does one convert bitmapimage to a stream or byte array?

Source: Internet
Author: User

The previous article "using base64 encoding in Silverlight" mentioned that the writeablebitmap object can be converted to a base64 string by using fluxjpeg, while the writeablebitmap can be directly constructed from bitmapsource, so... the problem is solved.

 

First, convert bitmapimage to writeablebitmap, and then obtain the base64 string. Then, you can obtain the array of base64 byte [], and then convert byte [] to stream.

 

KeyCode:

1
2
3 Writeablebitmap WB =   New Writeablebitmap (IMG. Source As Bitmapsource ); // Convert an image object to writeablebitmap
4
5 Byte [] B = Convert. frombase64string (getbase64image (WB )); // Get byte array
6

 

Restore byte [] to an image:

1 Byte [] B = ... // Here, B is the base64 encoded byte array generated above.
2 Memorystream MS =   New Memorystream (B );
3 Bitmapimage bitimage =   New Bitmapimage ();
4 Bitimage. setsource (MS );
5 Img2.source = Bitimage;

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.