问题描述
我想与嵌入式图像聊天.
I want a chat with inline images.
richtextbox很好,因为我可以在其中放置图像,但是我想单独发送文本/图像.
The richtextbox is good, because I can place images in it, but I want to send the text / images separate.
- 首先:发送文本(并在文本中放置图片占位符).
- 秒:发送图像并将其替换为占位符.
为此,我需要删除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;
}
}
}
}
}
}
这篇关于在RichTextBox中查找所有图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!