You can convert to a base64 string and place it in src
of the image:
I will consider that you have a System.Drawing.Image
.
First, convert to a byte array ( byte[]
):
/// <summary>
/// Converte um objeto System.Drawing.Image em um array de bytes
/// </summary>
/// <param name="foto">System.Drawing.Image</param>
/// <returns>byte[]</returns>
public static byte[] ConvertImageToByte(System.Drawing.Image foto, System.Drawing.Imaging.ImageFormat format )
{
if (foto != null)
{
using (MemoryStream stream = new MemoryStream())
{
foto.Save(stream, format);
//stream.Flush();
byte[] pic = stream.ToArray();
return pic;
}
}
else return null;
}
-Using the function:
System.Drawing.Image imagem = .... Origem da sua imagem;
byte[] bImage = ConvertImageToByte(imagem,System.Drawing.Imaging.ImageFormat.Png);
Then, convert byte[]
to string
:
string base64String = Convert.ToBase64String(bImage , 0, bImage.Length);
Then put it in the html:
string html = "<img class=""plan-cover"" src=""data:image/png;base64," + base64String + """>";
Obs. If you need to set the image size (smaller than the original), it makes sense to resize the Image
object and not html
. The amount of data sent will be only what is needed.