从转换的Word文档图像转换成位图对象 [英] Converting images from word document into bitmap object

查看:275
本文介绍了从转换的Word文档图像转换成位图对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于每个项目的要求,我们需要从word文档图像转换成位图对象。为了实现这一目标,我们试图inlineshape对象转换的Microsoft.Office.Interop.Word DLL成位图。但是无法获得成功,得到剪贴板对象为空。请找到code,我们尝试了如下;

As per project requirement we need to convert images from word document into bitmap object. To achieve this we tried to convert inlineshape object from Microsoft.Office.Interop.Word dll into bitmap. However unable to get success, getting clipboard object as null. Please find the code which we tried as below;

using System.Drawing;
using Microsoft.Office.Interop.Word;
namespace WordApp1
{
    class Program
    {
        static void Main(string[] args)
        {
           Application wordApp = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
           Documents documents = wordApp.Documents;

           Document d = null;
           foreach (Document document in documents)
           {
              if (document.ActiveWindow.Caption.Contains("{Word document name}"))
              {
                 d = document;
              }
           }

           foreach (InlineShape shape in d.InlineShapes)
           {
              shape.Range.Select();
              d.ActiveWindow.Selection.Range.CopyAsPicture();
              System.Windows.Forms.IDataObject dobj = System.Windows.Forms.Clipboard.GetDataObject();  //Getting clipboard object as null
              if(dobj.GetDataPresent(typeof(System.Drawing.Bitmap)))
              {
                 Bitmap bmp;
                 System.IO.MemoryStream ms = new System.IO.MemoryStream();
                 bmp = (Bitmap)dobj.GetData(typeof(System.Drawing.Bitmap));
              }
            }
        }        
     }
 }

有没有人曾在转换文字图像转换成位图?这将是很大的帮助,如果你能指导我们如何与转换从Word文档图像转换成位图对象继续前进。

Does anyone has worked on converting word images into bitmap? It would be great help if you could guide us how to go ahead with converting images from word document into bitmap object.

推荐答案

解决这个职位: http://stackoverflow.com/ A /一百零七万一千二百十二分之七百九十三万七千五百九十零 这是一个与STAThread一个问题:

Resolved in this post: http://stackoverflow.com/a/7937590/1071212 It's a problem with STAThread:

Thread thread = new Thread([Method]);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();

这篇关于从转换的Word文档图像转换成位图对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆