You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.4 KiB
78 lines
2.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ShenTun.ImageCollection.Common
|
|
{
|
|
public class ImageHelper
|
|
{
|
|
public static string ConvertImageToBase64(Image file)
|
|
{
|
|
using (MemoryStream memoryStream = new MemoryStream())
|
|
{
|
|
file.Save(memoryStream, file.RawFormat);
|
|
byte[] imageBytes = memoryStream.ToArray();
|
|
return Convert.ToBase64String(imageBytes);
|
|
}
|
|
}
|
|
|
|
public static Image ConvertBase64ToImage(string base64String)
|
|
{
|
|
byte[] imageBytes = Convert.FromBase64String(base64String);
|
|
using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
|
|
{
|
|
ms.Write(imageBytes, 0, imageBytes.Length);
|
|
return Image.FromStream(ms, true);
|
|
}
|
|
}
|
|
|
|
public static Image GetImage(byte[] str)
|
|
{
|
|
MemoryStream ms = new MemoryStream(str);
|
|
Image img = System.Drawing.Image.FromStream(ms);
|
|
return img;
|
|
}
|
|
public static Image GetImage(MemoryStream mstr)
|
|
{
|
|
MemoryStream ms = mstr;
|
|
Image img = System.Drawing.Image.FromStream(ms);
|
|
return img;
|
|
}
|
|
public static ImageCodecInfo GetEncoder(ImageFormat format)
|
|
{
|
|
|
|
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
|
|
|
|
foreach (ImageCodecInfo codec in codecs)
|
|
{
|
|
if (codec.FormatID == format.Guid)
|
|
{
|
|
return codec;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static string GetLoaclPath(string path,string dirName)
|
|
{
|
|
DateTime dt = DateTime.Now;
|
|
string year = dt.Year.ToString();
|
|
string month = dt.Month.ToString();
|
|
string day = dt.Day.ToString();
|
|
string file_path = path + "\\" + year + "\\" + month + "\\" + day + "\\" + dirName;
|
|
//如果日期的文件夹不存在
|
|
if (!Directory.Exists(file_path))
|
|
{
|
|
//创建一个日期的文件夹
|
|
Directory.CreateDirectory(file_path);
|
|
}
|
|
|
|
return file_path;
|
|
}
|
|
}
|
|
}
|