这是原图
变成了这样的了:
这样就看的不是很清楚了,我将word 中的这部分图另存出来的时候如何保持原样呢

解决方案 »

  1.   

    对了我是通过剪切板copy的图片在存的附上代码:
    public static void add()
            {
                object Nothing = System.Reflection.Missing.Value;
                object filename = "D:\\公式测试.docx";
                Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
                Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Open(ref filename, 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);            //循环文章中的各个章节
                foreach (Microsoft.Office.Interop.Word.Paragraph item in WordDoc.Paragraphs)
                {
                    if (item != null)
                    {
                        if (item.Range.Text.Trim() != "")
                        {
                            //判断该范围内是否存在图片
                            if (item.Range.InlineShapes.Count != 0)
                            {
                                foreach (Microsoft.Office.Interop.Word.InlineShape shape in item.Range.InlineShapes)
                                {
                                  
                                    //判断公式类型
                                    if (shape.Type == Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapeEmbeddedOLEObject)
                                    {                                    //利用剪贴板保存数据
                                        shape.Select(); //选定当前图片
                                        WordApp.Selection.Copy();//copy当前图片
                                        //使用剪切板
                                        if (Clipboard.ContainsImage())
                                        {
                                            //用bitmap另存图片
                                            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Clipboard.GetImage());
                                            //定义文件路径
                                            String path = "D:\\images\\";
                                            //如果文件路径不存在就创建
                                             if (!Directory.Exists(path))
                                                   Directory.CreateDirectory(path);
                                            //定义图片名称
                                           String fileName = System.Guid.NewGuid() + ".png";
                                            //保存图片
                                            bmp.Save(path + fileName, System.Drawing.Imaging.ImageFormat.Png);
                                            bmp.Dispose();
                                            //获取当前文档额selection
                                            var mySel = WordApp.Selection;
                                            var anchor = mySel.Range; //获取所在光标的range对象
                                            //添加图片
                                            InlineShape inlineShape = WordDoc.InlineShapes.AddPicture(path + fileName, false, true, anchor);
                                            //设置嵌入
                                           inlineShape.ConvertToShape().WrapFormat.Type = WdWrapType.wdWrapInline;
                                            //删除原图
                                           shape.Delete();
                                        }
                                    }
                                }
                            }                    }
                    }
                }            WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
                WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
            }