gpt4 book ai didi

c# - 通过 C# 将图片添加到 powerpoint 幻灯片抛出远程过程调用失败。 (来自 HRESULT : 0x800706BE) 的异常

转载 作者:太空宇宙 更新时间:2023-11-03 11:02:56 28 4
gpt4 key购买 nike

大家好,

我这里有一段代码:

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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com