How to embed an Image Stream to MailMessage

后端 未结 5 641
青春惊慌失措
青春惊慌失措 2020-12-09 10:03

I\'m having some difficulty embedding an image from the Properties.Resources to a MailMessage, currently the image does not show in the email i receive.

I have succe

5条回答
  •  时光说笑
    2020-12-09 10:43

    Ok i have solved the problem.

    Instead of using the BitMap save method I converted the BitMap to Byte[] and gave the memory stream the Byte[]

    Did not work :

     b.Save(logo, ImageFormat.Jpeg);
    

    Did Work:

    Bitmap b = new Bitmap(Properties.Resources.companyLogo);
    ImageConverter ic = new ImageConverter();
    Byte [] ba = (Byte[]) ic.ConvertTo(b,typeof(Byte[]));
    MemoryStream logo = new MemoryStream(ba);
    

    I think it has something to do with the Bitmap.Save method, in the MSDN lib it mentioned that the stream has to have an offset of 0.

提交回复
热议问题