点滴积累,融会贯通

-----喜欢一切有兴趣的东西

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

先将BitmapImage转化为WriteableBitmap,然后得到base64字符串,然后可以得到base64的byte[]数组,再然后您可以把byte[]变成Stream

关键代码:

WriteableBitmap wb = new WriteableBitmap(img.Source as BitmapSource);//将Image对象转换为WriteableBitmap
byte[] b = Convert.FromBase64String(GetBase64Image(wb));//得到byte数组

将byte[]还原为图片:

byte[] b = ...//这里的b为上面生成的base64编码的byte数组
MemoryStream ms = new MemoryStream(b);
BitmapImage bitImage = new BitmapImage();
bitImage.SetSource(ms);
img2.Source = bitImage;

posted on 2010-08-05 15:35  小寒  阅读(1261)  评论(0编辑  收藏  举报