I have a Dot Net Frameworks code that gets a base64 string from an image.
private string ImageToBase64(string value)
{
try
{
using (Image image = Image.FromFile(value))
{
using (MemoryStream m = new MemoryStream())
{
image.Save(m, image.RawFormat);
byte[] imageBytes = m.ToArray();
// Convert byte[] to Base64 String
return $"data:image/jpeg;base64,{Convert.ToBase64String(imageBytes)}";
}
}
}
catch(Exception)
{
return "";
}
}
I'm using .Net 6, so I added the following dll: dotnet add package System.Drawing.Common - version 6.0.0 But the compiler says the code is for Windows only, I would like to know if there is a way to make this code cross-platform?