this might sound like a repost of a question already asked. However, I have spent a few days looking through and testing many different examples from a number of different websites (incl. stackoveflow.com). Up to now, I got mostly undesired results and am a bit lost as to how to achieve this or something which produces good results? If anyone is able to help I would greatly appreciate it!
I work in VB.NET and use Visual Studio 2015.
My objective is to get a crisp image in the resulting RTF file when I open it in a text editor (I use WPS Office). However, the low quality, out of focus image I have been getting in the final RTF document is not a good header for the description I want to use it for! Nor will it look good after printing! I am not looking for a thumbnail image as the image is required for a larger document header.
Most solutions I have tried deal with resizing an image and then pasting it into a Rich Text Box(RTB).
However, although I have tried using interpolation, antialiasing, etc., the results are not great. For resizing, I have tried examples which use division, percentage, etc.
I am working on an app for my own personal use that "pastes" a screenshot of an active solution/app (i.e. bitmap) into a Picture Box(PB) and into an RTB using the clipboard, title is appended then text added manually in the RTB and the result is saved as an RTF file.
Image Quality issues I have found:
- Pasting an image after resizing/scaling the original (or a copy) in the Picture Box reduces quality?
- Saving to an RTF file or opening the RTF file in a text editor reduces quality? (Not sure which causes the issue?)
Both these processes result in a low quality, out of focus image (with or without interpolation, smoothing, antialiasing, etc.)? So, it seems to me that resizing before pasting reduces quality. I have tried pasting directly from the clipboard and also copying the image from the Picture Box to clipboard, then pasting to RTB. Both these procedures produce good results!
To be objective, I cannot share all the code I have tested, but share below a simple example of code which produces the best image quality for me, i.e. just simply pasting the screenshot directly from the clipboard to the RTB. However, the resulting image after pasting into the RTB has not been resized and is therefore too big. I don't want to manually resize the image in the RTF document as this would be an extremely repetitive task!
After pasting the bitmap into the RTF, I have used the Select All or Selection Start - 1 methods to select the image in the RTB, but to frame my question, "How can I resize the image in the RTB?"
You might ask why I want to do this. Well, pasting the bitmap directly into the RTB gives me the same quality image as the one in the Picture Box. There is a slight loss after saving to an RTF file and opening it in a text editor, but the quality is much better than the other methods mentioned above (i.e. resize then paste)! So, I got curious to attempt to paste and then resize! Here is my code:
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()
End Sub