using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media.Imaging; namespace RichCreator.Utility { public class ImageHelper { /// /// bitmap转为bitmapImage /// /// /// public static BitmapImage BitmapToImageSource(System.Drawing.Image bitmap) { MemoryStream ms = new MemoryStream(); bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = ms; bitmapImage.EndInit(); return bitmapImage; } /// /// bitmap image 转为 bitmap /// /// /// public static System.Drawing.Bitmap BitmapImageToBitmap(BitmapSource source) { MemoryStream ms = new MemoryStream(); BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(source)); encoder.Save(ms); ms.Seek(0, SeekOrigin.Begin); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(ms); return bitmap; } } }