34 lines
945 B
C#
34 lines
945 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LibraryUtils.ImageConverter
|
|
{
|
|
public class ImageConverter
|
|
{
|
|
public static Image StringToImage(string bytes)
|
|
{
|
|
byte[] arrayimg = Convert.FromBase64String(bytes);
|
|
Image imageStr = Image.FromStream(new MemoryStream(arrayimg));
|
|
return imageStr;
|
|
}
|
|
|
|
public static string ImageToString(Image image)
|
|
{
|
|
using (var ms = new MemoryStream())
|
|
{
|
|
image.Save(ms, image.RawFormat);
|
|
byte[] imageBytes = ms.ToArray();
|
|
string base64String = Convert.ToBase64String(imageBytes);
|
|
return base64String;
|
|
}
|
|
}
|
|
public static byte[] StringToByteArray(string bytes)
|
|
{
|
|
return Convert.FromBase64String(bytes);
|
|
}
|
|
}
|
|
}
|