从VB.net中的RTF中提取图像 [英] Extract images from RTF in VB.net

查看:66
本文介绍了从VB.net中的RTF中提取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,您知道如何在VB.net中从RTF中提取图像吗?我搜索一些网站,但找不到答案。希望你能帮助我。谢谢。

解决方案

如果你想完全自己做,那么你需要阅读RTF规范,特别是图片和解析内容;



这是1.5的规格; http://www.biblioscape.com/rtf15_spec.htm#Heading49 [ ^ ]



(这是指向MS的V1.9.1规范的链接: http://www.microsoft.com/downloads/details.aspx?familyid=dd422b8d-ff06-4207-b476-6b5396a18a2b&displaylang=en&tm [ ^ ])



正如您将在规范中看到的那样,图片位于\ _pict控件标记下,标签和所有数据都包含在{}括号内,因此很简单然后挑选出所需的数据。从这里你可以解析出子标签来读取图像的类型,然后通过读取字节来重建它。



示例rtf图像元素的文件数据;

 {\ pict \wmetafile8 \ picw9604 \pich7064 \ picwgoal5445 \ pichgoal4005< br /> 
010009000003c039020000009739020000000400000003010800050000000b0200000000050000< br />
000c020b016b01030000001e0004 ........数据继续........ ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff<峰; br />
ffffffffffffffffffffffffffff000000040000002701ffff030000000000<峰; br />
}


最简单的方法是使用richtextbox的rtf属性,如下所示。

RichTextBox1.rtf



为了你保存得当,使用

RichTextBox1.rtf.Replace(\,\\)。

当您使用它来保存RichTextBox控件的内容时,您现在可以将它传递给Rtf属性以显示图像


Hello everyone,do you know how to extract images from RTF in VB.net? I search some websites and could not find a answer. Hope you could help me. Thanks.

解决方案

If you want to do it totally yourself then you will need to read the RTF specification, particularly pictures and parse the contents;

Here is the spec for 1.5; http://www.biblioscape.com/rtf15_spec.htm#Heading49[^]

(Here is a link to the V1.9.1 spec at MS: http://www.microsoft.com/downloads/details.aspx?familyid=dd422b8d-ff06-4207-b476-6b5396a18a2b&displaylang=en&tm[^])

As you will see in the spec, picture are under the \pict control tag, and the tag and all the data are enclosed withinn { } brackets, so it is simple to then pick out the data required. From this you can parse out the sub tags to read the type of image and then reconstruct it by reading the bytes.

Sample rtf file data for a picture element;

{\pict\wmetafile8\picw9604\pich7064\picwgoal5445\pichgoal4005 <br />
010009000003c039020000009739020000000400000003010800050000000b0200000000050000<br />
000c020b016b01030000001e0004........data continues........ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff<br />
ffffffffffffffffffffffffffff000000040000002701ffff030000000000<br />
}


The simplest way of doing just this is by using rtf property of the richtextbox as below.
RichTextBox1.rtf

for you to save properly, use
RichTextBox1.rtf.Replace("\","\\").
When you use this to save the content of the RichTextBox control, you can now pass it to the Rtf property to display the image


这篇关于从VB.net中的RTF中提取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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