如何使用c#从word文档中读取visio对象并保存为一张清晰的jpg格式图片?

speedneeder 2011-07-18 10:11:10
如题,我的需求不难就是从一个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 + "处理完毕!");

}
...全文
715 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxiju203 2011-07-18
  • 打赏
  • 举报
回复
应该有设置图片质量的方法的吧
speedneeder 2011-07-18
  • 打赏
  • 举报
回复
沉的好快。。。。。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧