? 對于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對象