您的位置:首页 > 其它

WP8 中常用的 WriteableBitmap和BitmapImage相互转换

2014-09-14 16:21 621 查看
一、WriteableBitmap转为BitmapImage对象

var bi= new BitmapImage();
bi.SetSource(wb.ToImage().ToStream()); //其中wb是WriteableBitmap对象。
二、BitmapImage转为WriteableBitmap对象
//这里就转换完成了
WriteableBitmap wb = new WriteableBitmap(bi.Source as BitmapSource);

三、将WriteableBitmap转为字节数组
byte[] b = Convert.FromBase64String(GetBase64Image(wb));
//这里通过base64间接处理,效率不是很高。

四、将字节数组转为BitmapImage对象
MemoryStream ms = new MemoryStream(b); // b为byte[]
BitmapImage bi = new BitmapImage();
bi.SetSource(ms);
img.Source = bi; //这里img为XAML的Image对象
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  wp8 图片 转换