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
|
{
|
|
/// <summary>
|
/// bitmap转为bitmapImage
|
/// </summary>
|
/// <param name="bitmap"></param>
|
/// <returns></returns>
|
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;
|
}
|
|
/// <summary>
|
/// bitmap image 转为 bitmap
|
/// </summary>
|
/// <param name="source"></param>
|
/// <returns></returns>
|
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;
|
}
|
}
|
}
|