从RichTextBox中提取图像 [英] Extracting images from RichTextBox

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

问题描述

我有一个应用程序,用户可以将图像插入RichTextBox。我希望能够用一些令牌替换RTF中的所有图像,并将图像存储在单独的文件中。我稍后会将图像注入RTF。

I have an application where users may insert images into a RichTextBox. I'd like to be able to replace all the images in the RTF with some token and store the images in separate files. I'll inject the images back into the RTF later.

我设法让插件正常工作,但最终还是试图通过剪贴板粘贴它们(非常像在C#中将图像插入RTF文档中

I've managed to get the insertion working but ended up resorting to pasting them via the Clipboard (very like Insert an image into RTF document in C#).

现在的麻烦是如何提取图像。

The trouble now is how to extract the images.


  1. 如何以编程方式选择RichTextBox中的图像?

  1. How do I programatically select an image in a RichTextBox?

我是否必须通过剪贴板返回?类似于:

Do I have to go back through the clipboard? Something like:

IDataObject data = Clipboard.GetDataObject();
Clipboard.Clear();

_RichTextBox.Select(/* The image */);
_RichTextBox.Copy();

Image img = Clipboard.GetImage();
img.Save("myImage.png", System.Drawing.Imaging.ImageFormat.Png);

Clipboard.Clear();
Clipboard.SetDataObject(data);


  • 是否有一个更优雅的解决方案,不需要通过剪贴板?

  • Is there a more elegant solution that doesn't require going through the clipboard?

    感谢您的帮助!

    推荐答案

    图片看起来像这样:

    {\*\shppict {\pict \emfblip ..... }}{\nonshppict {\pict ....}}
    

    甚至

    {\pict ...}
    

    您可以检查包含图片的文档的rtf并编写正则表达式来提取图像(用标记替换它们)。
    另一个正则表达式替换可以恢复图像。

    You can check the rtf of the document containing the picture and write a regular expression to extract the images (replacing them with tokens). Another regex replace can restore the images.

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

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