大家好,
我这里有一段代码:
System.Net.WebClient wc = new System.Net.WebClient();
byte[] data = wc.DownloadData(xmlTempNode.Attributes["imageurl"].Value.ToString());
MemoryStream ms = new MemoryStream(data);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
string strImagePath = pptdirectoryPath + "\\" + currentSlide + "_" + shape.Id + ".png";
img.Save(strImagePath);
tempSlide.Shapes.AddPicture(strImagePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, Convert.ToInt32(xmlTempNode.Attributes["imgwidth"].Value), Convert.ToInt32(xmlTempNode.Attributes["imgheight"].Value));
shape.Delete();
tempSlide.Shapes.AddPicture
对于较小的图像工作正常,当分辨率较高时它会失败(这里失败意味着无限长时间未收到响应并在刷新页面时抛出异常)。
异常消息:远程过程调用失败。 (HRESULT 异常:0x800706BE) 在 Microsoft.Office.Interop.PowerPoint.Shapes.AddPicture(字符串文件名、MsoTriState LinkToFile、MsoTriState SaveWithDocument、单左、单顶部、单宽度、单高度)。
如有任何帮助,我们将不胜感激。
最佳答案
终于解决了这个问题。使用下面的代码来添加图片
tempSlide.Shapes.AddPicture(strImagePath, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Convert.ToInt32(shape.Left), Convert.ToInt32(shape.Top), Convert.ToInt32(xmlTempNode.Attributes["imgwidth"].Value), Convert.ToInt32(xmlTempNode.Attributes["imgheight"].Value));//load new image to shape
问题是,我为 LinkToFile 发送 msoFalse,为 SaveWithDocument 发送 msoTrue。
现在,为 LinkToFile 传递 msoTrue 并为 SaveWithDocument 传递 msoFalse 完成了我的工作。
快乐编码..
关于c# - 通过 C# 添加图片到 powerpoint 幻灯片会抛出远程过程调用失败。 (HRESULT : 0x800706BE) 的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17024989/