- Bitmap to ImageSource
将得到的Bitmap对象转换为wpf常用的Imagesource对象
BitmapSource bs = Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
得到的BitmapSource是Imagesource的子类
- ImageSource to Bitmap
首先得到ImageSource对象_imagesource System.IO.MemoryStream ms = new System.IO.MemoryStream(); BmpBitmapEncoder encoder = new BmpBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create((BitmapSource)_imagesource)); encoder.Save(ms); Bitmap bp = new Bitmap(ms); ms.Close();