Reputation: 699
I get "System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.' (on save) " when running
private void SaveImage(string base64, string imageName)
{
using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(base64)))
{
using (Bitmap bm2 = new Bitmap(ms))
{
bm2.Save(imageName, ImageFormat.Png);
}
}
}
on azure. The base64 strig is correct since on https://base64.guru/converter/decode/image it's decoding fine. I'm running it on azure functions.
Upvotes: 0
Views: 61
Reputation: 699
The problem was the path. so the solution is to use Path.Combine and Path.GetTempPath
private void SaveImage(string base64, string imageName)
{
using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(base64)))
{
using (Bitmap bm2 = new Bitmap(ms))
{
bm2.Save(imageName, ImageFormat.Png);
}
}
}
var fileName = ...
var filePath = Path.Combine(Path.GetTempPath(), fileName);
SaveImage(base64, filePath);
Upvotes: 0