Insert Image into an HTML file

Asked

Viewed 82 times

0

I am creating an HTML file and need to insert an image that is in the Resources for this I am trying to use the following code:

private byte[] turnImageToByteArray(System.Drawing.Image img)
    {
        MemoryStream ms = new MemoryStream();
        img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
        return ms.ToArray();
    }

 System.Drawing.Image img = MeuProjeto.Properties.Resources.Fundo;
 byte[] imgBytes = turnImageToByteArray(img);
 string teste = "<img src="[email protected]("data: image / png; base64,{0}", Convert.ToBase64String(imgBytes))+"/>";

 sb.Append("<tr>").Append(teste).Append("</TR><br>");

but when I load the HTML file it always appears that the image is wrong, can you help me where the error is? I looked at several examples and they all follow this way.

I switched to:

byte[] imgBytes = turnImageToByteArray(img);
            string imgString = Convert.ToBase64String(imgBytes);
            string teste = @String.Format("<img src=\"data:image/Png;base64,{0}\">", imgString);

and now this is coming up: inserir a descrição da imagem aqui

note that it is loading an image with error

  • It would be good to report the error to help clarify the problem.

  • simply does not appear the image is as if it has not been added

  • after much searching, was not working because I was putting as Toupper and asasim the path was not located

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.