C#/ WPF:RichTextBox的:查找所有图片

编程入门 行业动态 更新时间:2024-10-25 19:33:50
本文介绍了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的:查找所有图片

本文发布于:2023-11-12 01:11:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580085.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图片   WPF   RichTextBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!