C#/ WPF:RichTextBox的:查找所有图片 [英] C# / WPF: Richtextbox: Find all Images

查看:1371
本文介绍了C#/ WPF:RichTextBox的:查找所有图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想与内联图像聊天。
RichTextBox的好,因为我可以将图像,但我要发送的文字/图片分开。
-first:发送文本(并将在文本中的图像占位符)。
- 第二:发送图像和占位符代替它。

i want a chat with inline images. The richtextbox good, because i can place images in it, but i want to send the text / images separate. -first: send the text (and place a image-placeholder in the text). -second: send the image and replace it with the placeholder.

有关,我需要删除所有图像RichTextBox的(并把他们分开)。
,而我怎么能找到图片

For that i need to remove all images in the richtextbox (and send them separate). But how can i find the images?

和BTW:??是否有可能重新调整依赖于RichTextBox的宽度的图片

And btw: Is it possible to rescale the image dependent on the width of the richtextbox?

感谢您:)

推荐答案

要找到所有图像在一个RichTextBox,你需要通过所有段和内联遍历;然后,你可以做任何你需要的图片。例如,下面的代码将增加一个RichTextBox内的所有图像的大小(1个像素)。

To find all images in a RichTextBox, you need to traverse through all Paragraphs and its Inlines; and then you can do whatever you need with the image. For example, the following code will increase the size (by 1 pixel) of all images inside a RichTextBox.

    public static void ResizeRtbImages(RichTextBox rtb)
    {
        foreach (Block block in rtb.Blocks)
        {
            if (block is Paragraph)
            {
                Paragraph paragraph = (Paragraph)block;
                foreach (Inline inline in paragraph.Inlines)
                {
                    if (inline is InlineUIContainer)
                    {
                        InlineUIContainer uiContainer = (InlineUIContainer)inline;
                        if (uiContainer.Child is Image)
                        {
                            Image image = (Image)uiContainer.Child;
                            image.Width = image.ActualWidth + 1;
                            image.Height = image.ActualHeight + 1;
                        }
                    }
                }
            }
        }
    }

这篇关于C#/ WPF:RichTextBox的:查找所有图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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