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;