You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using Image = System.Drawing.Image;
|
|
|
|
|
|
|
|
|
|
namespace Hopetry.App.Common;
|
|
|
|
|
|
|
|
|
|
public class ImageHelper
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图片转换成字节流
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="img">要转换的Image对象</param>
|
|
|
|
|
/// <returns>转换后返回的字节流</returns>
|
|
|
|
|
public static Stream ImgToStream(Image img)
|
|
|
|
|
{
|
|
|
|
|
byte[] imgByte = ImgToByt(img);
|
|
|
|
|
//img.Save(ms, img.RawFormat);//System.Drawing.Imaging.ImageFormat.Jpeg
|
|
|
|
|
Stream stream = new MemoryStream(imgByte);
|
|
|
|
|
return stream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图片转换成字节流
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="img">要转换的Image对象</param>
|
|
|
|
|
/// <returns>转换后返回的字节流</returns>
|
|
|
|
|
public static byte[] ImgToByt(Image img)
|
|
|
|
|
{
|
|
|
|
|
MemoryStream ms = new MemoryStream();
|
|
|
|
|
byte[] imagedata = null;
|
|
|
|
|
img.Save(ms, ImageFormat.Jpeg);
|
|
|
|
|
imagedata = ms.GetBuffer();
|
|
|
|
|
return imagedata;
|
|
|
|
|
}
|
|
|
|
|
}
|