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.
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.
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?
Thanks for your help!