如何使用c#从word文档中读取visio对象并保存为一张清晰的jpg格式图片?
如题,我的需求不难就是从一个doc文档(该文档只有一个visio图形)之中读取一个visio格式的图形,并将这个图形保存为jpg图片。
实现的原理和方法都有了,采用复制到剪贴板并保存为jpg的方法,但问题是使用程序保存之后的jpg图形和我手动操作ctrl+c,再ctrl+v和图形比起来清晰度差了很多。
我试着追踪了一下,发现问题出在将图形复制到剪贴板的过程上,在程序执行将图形复制到剪贴板的那一步,剪贴板上得到的就是一个不清晰的的图形,但手动执行ctrl+c则是清晰的。
附上实现的简单代码(不全,只贴了最主要的部分),请大家帮我看看是什么原因:
private void buttonSave_Click(object sender, EventArgs e)
{
MSWord.Application wordApp; //Word应用程序变量
MSWord.Document wordDoc; //Word文档变量
object srcPath = @"d:\test\test.doc"; //路径
wordApp = new MSWord.Application(); //初始化
wordDoc = wordApp.Documents.Open(ref srcPath, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
object format = MSWord.WdSaveFormat.wdFormatDocument97;
foreach (MSWord.InlineShape ish in wordDoc.InlineShapes)
{
ish.Select();
wordApp.Selection.CopyAsPicture(); //问题就在这一步,剪贴板上得到的就是一个不清晰的图片
Clipboard.GetImage().Save("d:\\test\\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
//关闭wordDoc文档对象
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
//关闭wordApp组件对象
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
MessageBox.Show(srcPath + "处理完毕!");
}
实现的原理和方法都有了,采用复制到剪贴板并保存为jpg的方法,但问题是使用程序保存之后的jpg图形和我手动操作ctrl+c,再ctrl+v和图形比起来清晰度差了很多。
我试着追踪了一下,发现问题出在将图形复制到剪贴板的过程上,在程序执行将图形复制到剪贴板的那一步,剪贴板上得到的就是一个不清晰的的图形,但手动执行ctrl+c则是清晰的。
附上实现的简单代码(不全,只贴了最主要的部分),请大家帮我看看是什么原因:
private void buttonSave_Click(object sender, EventArgs e)
{
MSWord.Application wordApp; //Word应用程序变量
MSWord.Document wordDoc; //Word文档变量
object srcPath = @"d:\test\test.doc"; //路径
wordApp = new MSWord.Application(); //初始化
wordDoc = wordApp.Documents.Open(ref srcPath, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
object format = MSWord.WdSaveFormat.wdFormatDocument97;
foreach (MSWord.InlineShape ish in wordDoc.InlineShapes)
{
ish.Select();
wordApp.Selection.CopyAsPicture(); //问题就在这一步,剪贴板上得到的就是一个不清晰的图片
Clipboard.GetImage().Save("d:\\test\\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
//关闭wordDoc文档对象
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
//关闭wordApp组件对象
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
MessageBox.Show(srcPath + "处理完毕!");
}
...全文
相关推荐
c#用aspose.word读取word文件内容,并显示图片
在探讨如何利用C#结合Aspose.Word库读取Word文档内容并显示其中的图片之前,我们首先需要了解几个关键的概念和技术点。
C#操作word文档 C#实现Word中表格信息读取
### 一、使用C#操作Word文档并插入图片在C#中操作Word文档通常需要用到`Microsoft.Office.Interop.Word`命名空间下的类库。
C#读取word并转为html格式
以上就是关于使用C#读取Word文档并转换为HTML格式的详细说明。希望对你有所帮助!
c#根据word模板生成word文档
**保存和关闭文档**:生成新内容后,使用`Document.SaveAs`方法将文档保存到指定位置,并通过`Document.Close`方法关闭文档,释放资源。7.
C#richTextBox显示和保存带格式的Word文档
本文将深入探讨如何利用C#的`richtextbox`来显示、保存以及另存为带格式的Word文档。


