namespaces used :
using System.Windows.Controls; using System.IO; using System.Windows.Media.Imaging;
using System.Windows.Media;


Stream to String :

BitmapImage bimg = new BitmapImage();
bimg.SetSource(photoStream); //photoStream is a stream containing data for a photo

byte[] bytearray = null;
using (MemoryStream ms = new MemoryStream())
{
WriteableBitmap wbitmp = new WriteableBitmap(bimg);
wbimg.SaveJpeg(ms, wbitmp.PixelWidth, wbitmp.PixelHeight, 0, 100);
ms.Seek(0, SeekOrigin.Begin);
bytearray = ms.GetBuffer();
}
string str = Convert.ToBase64String(bytearray);

String to Stream and then to Image :

byte[] data = Convert.FromBase64String(str);

Stream memStream = new MemoryStream(data);

WriteableBitmap wbimg = PictureDecoder.DecodeJpeg(memStream);

image1.Source = wbimg;
posted on 2011-06-03 12:16  tonylx  阅读(251)  评论(0)    收藏  举报