有关WriteableBitmap和BitmapImage之间的相互转换
  对于WP7中图形处理有关WriteableBitmap和BitmapImage之间的相互转换,给大家几个简单实用的方法。
一、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对象
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号