Hi, I am creating a program that saves and displays images and a text description. However, I am struggling to discover how to generate the RTF code for the image and text in my program.
I have achieved this manually saving an image/text or both in an editor then opening the file in Notepad. Also, saving the resulting RTF code in Notepad with the .rtf extension creates an RTF file which displays the image and text perfectly in the editor.
I found an example of the function I am looking for (i.e.
c# - How can I insert an image into a RichTextBox? - Stack Overflow[
^] ), but it's an exec file.
I have never worked with RTF code and have been searching for over a week now. I have read a lot of documentation, but found no clear examples of how this is achieved in code?
Before someone suggested using RTF code I was using the clipboard to paste (as in the code below), but this greatly reduces the image quality. I have found that using RTF code resolves a number of problems:
- Saving multiple items on a form (i.e. Picture Box image and RTF text)
- Opening/extracting multiple items from file
- Reduction in image quality (i.e. resizing, copy and paste, etc.)
- Resizing an image (I also need to achieve this in code, but don't know how to parse the RTF code to alter the picwgoal and pichgoal values?)
The steps I would like to achieve in my program:
-
Screenshot and Description: I already have this working. The user captures a screenshot, pastes it into the Picture Box, screenshot is pasted into Rich Text Box(RTB), Dummy Title is appended.
-
Generate RTF code: I don't know how to achieve this? I plan to generate RTF code for the image in the Picture Box, paste the code into a hidden RTB, generate RTF code for the Description text, append this code to the image code in the hidden RTB.
-
Save the RTF code: Saving the RTF code for the image and text as an .rtf file combines both image and text into one .rtf file! I already have a save routine for saving .rtf files!
-
Browse files: Opening the .rtf file displays an image and text in the same file!
If anyone can help me with a example of how to generate/convert RTF code, I would be extremely grateful!
What I have tried:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Check whether PB1 is empty:
If PictureBox1.Image Is Nothing Then
'Get image from clipboard to PB1:
PictureBox1.Image = My.Computer.Clipboard.GetImage
'Resize image to fit PB1:
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
'Paste image:
RichTextBox1.Paste()