开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 4470|回复: 0

【RichEditControl】如何提取图片

[复制链接]

0

精华

0

贡献

0

赞扬

帖子
25
软币
109
在线时间
10 小时
注册时间
2015-10-22
发表于 2016-3-1 18:02:10 | 显示全部楼层 |阅读模式
[C#] 纯文本查看 复制代码
private void GetImagesFromWord(string strFileName)
        {
            using (RichEditDocumentServer srv = new RichEditDocumentServer())
            {
                srv.LoadDocument(strFileName);
                DevExpress.XtraRichEdit.API.Native.Document doc = srv.Document;
                DevExpress.XtraRichEdit.API.Native.ParagraphCollection parCol = doc.Paragraphs;
                DocumentImageCollection dic = doc.GetImages(doc.Range);
                if (dic.Count == 0)
                    return;
                //创建文件夹
                int index = strFileName.LastIndexOf('.');
                if (index == -1)
                    return;
                string strDir = strFileName.Substring(0, index);
                if(!Directory.Exists(strDir))
                    Directory.CreateDirectory(strDir);

               
                int i = 0;
                foreach (DocumentImage di in dic)
                {
                    i++;
                    string strNewFileName = strDir + "\\";
                    DevExpress.Office.Utils.OfficeImage officeImage = di.Image;
                    string strSuffix = i.ToString()+".";
                    switch (officeImage.RawFormat) { 
                        case DevExpress.Office.Utils.OfficeImageFormat.Bmp:
                            strSuffix += "bmp";
                            break;
                        case DevExpress.Office.Utils.OfficeImageFormat.Gif:
                            strSuffix += "gif";
                            break;
                        case DevExpress.Office.Utils.OfficeImageFormat.Jpeg:
                            strSuffix += "jpg";
                            break;
                        case DevExpress.Office.Utils.OfficeImageFormat.Png:
                            strSuffix += "png";
                            break;
                        case DevExpress.Office.Utils.OfficeImageFormat.Icon:
                            strSuffix += "ico";
                            break;
                        case DevExpress.Office.Utils.OfficeImageFormat.Emf:
                            strSuffix += "emf";
                            break;
                        case DevExpress.Office.Utils.OfficeImageFormat.Wmf:
                            strSuffix += "wmf";
                            break;
                       

                        default:
                            strSuffix += "bmp";
                            break;
                    }
                    strNewFileName += strSuffix;
                    File.WriteAllBytes(strNewFileName, officeImage.GetImageBytes(officeImage.RawFormat));
                }
                
            }
        }

回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-11-24 10:13

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表