直接上代码
using System; using System.Drawing; using System.IO; using System.Windows.Forms; using System.Windows.Media.Imaging; namespace CommonUtils { /// <summary> /// Windows图片处理 /// </summary> public static class WindowsImage { #region BitmapSource /// <summary> /// 获取图片源 /// </summary> public static BitmapSource GetSource(Stream stream) { //已验证stream不可关闭 return BitmapFrame.Create(stream); } /// <summary> /// 获取图片源 /// </summary> public static BitmapSource GetSource(Image image) { return GetSource(image.Stream()); } /// <summary> /// 获取图片源 /// </summary> public static BitmapSource GetSource(byte[] bytes) { return GetSource(bytes.ToStream()); } /// <summary> /// 获取图片源 /// </summary> public static BitmapSource GetSourceFromBase64(string base64) { return GetSource(base64.Base64Decode()); } /// <summary> /// 获取图片源 /// </summary> public static BitmapSource GetSourceFromUrlOrPath(string urlOrPath) { return new BitmapImage(new Uri(urlOrPath)); } #endregion /// <summary> /// 获取截屏 /// </summary> public static Bitmap GetScreenShoot() { Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics graphics = Graphics.FromImage(bitmap); graphics.CopyFromScreen(new Point(0, 0), new Point(0, 0), bitmap.Size); graphics.Dispose(); return bitmap; } } }
标签:return,BitmapSource,Stream,Url,System,static,GetSource,public From: https://www.cnblogs.com/webenh/p/17919223.html