链接资源中的图像网址

时间:2013-09-25 10:41:05

标签: c# image uri

我想在c#mail中嵌入来自网址的图片,我尝试使用此代码,但它无法正常工作

 LinkedResource logoHeader = null;
AlternateView av1 = AlternateView.CreateAlternateViewFromString(strBody, null,   MediaTypeNames.Text.Html);
logoHeader= new LinkedResource("some xyz.com");  
logoHeader.ContentId = "logoimage";
av1.LinkedResources.Add(logo);

2 个答案:

答案 0 :(得分:6)

string image = "example.com/image.jpg";
var webClient = new WebClient();
byte[] imageBytes = webClient.DownloadData(image);
MemoryStream ms = new MemoryStream(imageBytes);
LinkedResource resource = new LinkedResource(ms, MediaTypeNames.Image.Jpeg);

答案 1 :(得分:0)

AlternateView av = AlternateView.CreateAlternateViewFromString(str,null,MediaTypeNames.Text.Html);
LinkedResource lr = new LinkedResource("E:\\Photos\\hello.jpg",MediaTypeNames.Image.Jpeg);
lr.ContentId = "image1";
av.LinkedResources.Add(lr);
message.AlternateViews.Add(av);