我在使用 C# 和 Interop.Word 时遇到了一些图片问题。我想要将一张图片添加到我将要生成的文档的页眉中。我已经有了完美运行的代码。
section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddPicture(@"C:\Logo.jpg", ref x, ref x, ref x, ref x, ref x, ref x, ref x);
问题在于代码中无法使用
"C:\Logo.jpg"
,因为发布项目后,用户的C文件夹中很可能没有Logo.jpg。该图像已经在我的项目资源文件夹中。我以前使用过Image.FromFile("Logo.jpg")
,但是.AddPicture
需要一个字符串而不是一个图像。
有任何想法吗?
-- 编辑 --
在网上看到了这个:
string anyPath = @"C:\logo.jpg";
Properties.Resources.logo.Save(anyPath);
section.Headers.[...].Shapes.AddPicture(anyPath, ...
但是我仍然在GDI+中得到一个通用错误或者是未处理的ExternalException。