I want a chat with inline images.
The richtextbox is good, because I can place images in it, but I want to send the text / images separate.
For that I need to remove all images in the richtextbox (and send them separate). But how can I find the images?
And BTW: Is it possible to rescale the image dependent on the width of the richtextbox?
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;
}
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With