这里写目录标题 一级目录 Image转Base64String Base64String转Image 一级目录 Image转Base64String public string ImgToBase64String ( string PhotoPath ) { FileStream fs = new FileStream ( Photo
这里写目录标题
- 一级目录
- Image转Base64String
- Base64String转Image
一级目录
Image转Base64String
public string ImgToBase64String(string PhotoPath)
{
FileStream fs = new FileStream(PhotoPath, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int)fs.Length);
string base64String = Convert.ToBase64String(buffer);
return base64String;
}
Base64String转Image
public void Base64StringToImage(string strbase64)
{
try
{
byte[] arr = Convert.FromBase64String(strbase64);
MemoryStream ms = new MemoryStream(arr);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
img.Save($"C://Users//123//Desktop//图片//129.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
System.Console.WriteLine($"出问题了 {ex.Message}");
}
}