在电子邮件中附加多种图像格式,而不仅仅是JPG [英] Attach multiple image formats, not just JPG to email

查看:145
本文介绍了在电子邮件中附加多种图像格式,而不仅仅是JPG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我到目前为止所拥有的...

This is what i have so far...

 MemoryStream imgStream = new MemoryStream();
        System.Drawing.Image img = System.Drawing.Image.FromStream(fuImage.PostedFile.InputStream);
        string filename = fuImage.PostedFile.FileName;

        img.Save(imgStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        imgStream.Seek(0L, SeekOrigin.Begin);
        EmailMsg.Attachments.Add(new Attachment(imgStream, filename, System.Net.Mime.MediaTypeNames.Image.Jpeg));

因此,它可以很好地附加JPEG图像.但是我想对其进行更改,以便允许使用PNG和GIF.

So it attaches a JPEG image fine. But i want to change it so that it allows PNG's and GIFs.

推荐答案

您可能已经找到了这个答案,所以该答案适用于遇到此问题的其他任何人.

You've probably have found this answer by now, so this answer is for anyone else who runs into this issue.

    Image image = ConvertToImage(response);
    Stream imageStream = ToStream(image, ImageFormat.Png);
    LinkedResource logo = new LinkedResource(imageStream, "image/png");

上面是为我工作的示例,ConvertToImage返回System.Drawing.Image,而ToStream返回System.IO.Stream.

Above is a sample worked for me, ConvertToImage returns System.Drawing.Image and ToStream returns System.IO.Stream.

我希望这会有所帮助!

I hope this helps!

这篇关于在电子邮件中附加多种图像格式,而不仅仅是JPG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆