How do I Resize An Image In a RichTextBox? - vb.net

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

Related

Convert an embedded Excel Picture into an Object

I created a logo in Publisher.
Using TechSmith Snagit, I captured the image and saved as a JPEG.
I fetched the image inside of Excel and placed it in a properly sized cell(s)
I don't want to have a file that has the image (have seen in researching some solutions) -- Nevertheless, everything must be self-contained in my Excel vba Application.
Excel (2013) has a tendency to either erase the image or it creeps when the app is opened on other displays. (And it does this with ActiveX Controls, too)
So... a friend wrote code that stretches or centers ActiveX Controls inside cells. Works brilliantly, except I want to apply the code to the Picture (say Picture 12) ... the Logo ...
If I could convert the Picture into an Object (similar to a CommandButton or a SpinButton, I think the code would work.
My work around had been to insert the logo as a BitMap into a CommandButton, and then apply the stretching code to the button... BUT I have image size limitations and the Bitmap is of low resolution, which makes my beautiful logo look terrible.
Any suggestions would be very much appreciated.
maybe use base64
Inserting an Image into a sheet using Base64 in VBA?
https://www.base64-image.de/

Image recolour in Excel

I have a greyscale image with some transparent sections too. I would like to recolour this within excel (based on the value that a user types in a cell or something)
Manually, all I need to do is select the picture then in the ribbon 🡒 format 🡒 colour 🡒 more variations 🡒 more colours and select appropriately. I've tried the macro recorder on these steps but get nothing useful.
Searching the web has led me to believe that the Shape.PictureFormat.Recolor method, which I'm guessing is what I want, is only availible in Publisher. I'd rather not interface with thatfor portability reasons (in case publisher isn't installed), and I'd also like this to run as speedily as possible.
I've even considered converting the image to an array of bytes, performing the required pixel manipulations then converting back to an image, but I think that'll be slow. I also don't have a clue how.
Is there a method in VBA to recolour an image in this way, leaving alpha as it is? Perhaps with the use of an ActiveX image control? Here's an example image in case it's not clear
White 🡒 Green
Black 🡒 Black
Alpha 🡒 Alpha
If you can't find a pure object model based solution, you can try to modify the document xml. It is not the easiest of solutions, but it is far easier than pixel manipulation.
Do like this:
Save your workbook without modification
Do the color change
Save the file again, with a different file name
Unzip the two *.xlsx files you created
Analyze the differences. You'll most likely find it in the drawings folder
Recreate the changes in the xml of the second file in the first one and zip it back together. If that works, you now have a theoretical way to the solution.
If you get this to work, you can automate these steps.

Workaround for inlineshape.LinkFormat.Update

I am writing a Word 2007 document with a lot of images that are sure to change before the document is delivered. Therefore, I am inserting them in the document as links to PNG files. My problem is that if I select the image and execute:
Selection.InlineShapes(1).LinkFormat.Update
MsgBox Selection.InlineShapes(1).LinkFormat is Nothing
the message box displays "True". That is, the Update method broke the link.
I have tried using Selection.InlineShapes(1).Delete, followed by Selection.InlineShapes.AddPicture. This updates the image, but now I need to crop the image and that introduces its own set of problems. Before trying to deal with the cropping issues, I'm hoping that someone has a better way of updating the linked file.
BTW, closing the document and reopening it updates the image nicely as long as the filename has not changed. The point of the macro is to cope with filename changes, if necessary.

save textbox as picture in powerpoint_transparancy difficulties

In powerpoint 2010 I want to save an inserted textbox as a picture, which is simply done by right-clicking on the text box and save it. The saved image will however include a large amount of transparancy around the text. I am wondering whether this abundance of transparency around the text can be reduced, whithout using photo-editing programs.
I understand that powerpoint is not the right tool to use the beautifuly created texts for other purposes aside from office itself, however this would make things ten times easier for some coworkers of mine.
I hope someone can help me with this, also if it means using VBA or other (complex) codes/languages.
Thnx for your time.
Mike
Once you have typed your text in the textbox,
Copy the text box, right-click and paste as image
Now you have the image of the text box as you will get while saving that textbox as image - - using the save_as_image option
Select this image and click on format tab
You have an option to crop your image
Crop the image and save it as a picture

Can we resize a QR-Code?

Does anyone know if we can resize a QR-Code easily by using a proper vector program OR, is the size information contained on that code, hence, we will not be able to resize without changing the code ?
Thanks in advance.
You can resize as much as you want. The information is encoded in the pattern of the data, not in the size of the dots themselves. As long as a scanner can resolve properly between light/dark, the QR code should be readable at any size.
Update 2016: If someone happens to need to upscale a QR code image in some sort of browser/webview - you might get away with a simple CSS property:
img {
image-rendering: pixelated;
}
This way the upscaled image stays sharp.
See a comparison here: http://codepen.io/erkkit/pen/GodxGX
For high resolution (vector image) QR code for printing/publishing:
Get your free QR code
Right-click-and-save OR PrintScreen the QR code
Open/insert it in Photoshop, crop the QR code, and save as *.psd file (default Photoshop format)
Open that *.psd file with Adobe Illustrator – and you get the vector QR code. DONE! :)
Don't just re-size it that will make the edges blurry. You want it to have hard edges like MS-paint or the pencil brush in Photoshop. Open the file in Photoshop and go to IMAGE - RE-SIZE IMAGE and make sure Nearest Neighbor is selecting from the bottom drop down menu before you click OK
You CAN'T, not with the free QR generators. Unless you do some Adobe Illustrator tweaks with Live Trace/Paint afterwards. The abundant free QR generators are a joke when it comes to publishing the QR code you need. Resizing an originally low resolution image (the previous comment) for publishing/printing purposes is the most rediculous statement I've seen in a while. The guy doesn't know what he is talking about.