How to add dynamically created image to powerpoint slide? - vb.net

I am creating a PPT file with VB.NET and I would like to insert dynamically created images from memory into the slides, these images are screenshots being put into Image variables.
oSlide.Shapes.AddPicture("file location", False, True, 150, 150, 500, 350)
Is used to insert an image but it only accepts a file location.
I would rather not save all of the images I am creating to insert then delete off my drive. Does anyone have a solution?

Clipboard.SetImage(YouVariableHere) Load your image to the clipboard first
This function happens to take a System.Drawing.Image as it's argument
Shapes.Paste pastes whatever is currently on the clipboard.

Related

How to add a different audio file to each slide for narration?

I want to add a different audio file to each slide for narration.
I can use the ribbon to insert an audio file for each slide. Manually doing it takes forever.
I can't locate in the VBA PowerPoint docs what object to work with.
When I search for audio, insert audio etc. I get nothing helpful from MS PowerPoint docs.
To add audio file, use AddMediaObject2 method under Shapes object. (Documentation)
Example of adding an audio file to the first slide of your current presentation:
Application.ActivePresentation.Slides(1).Shapes.AddMediaObject2("Audio file path")
You can also set a variable to the Shape returned by the method for further modification:
Dim newAudio As Shape
Set newAudio = Application.ActivePresentation.Slides(1).Shapes.AddMediaObject2("Audio file path")

VBA to insert a blank ContentControlPicture at a specific location in Word doc

I've tried:
ActiveDocument.Range.ContentControls.Add (wdContentControlPicture)
But I get an error that says "Picture controls cannot be inserted around a selection which contains non-image content, floating images, or more than a single inline image"
I need to insert this control after ActiveDocument.Paragraphs(55) - is there any way to do this?

Show picture/image from userform in print header, VBA MS Project

I am making a template and thought to store our logo.jpg inside a userform. Then I'll call this userform and insert the logo in the print header for each "macro activated" print.
So far I have managed to print the image only as numbers. Bits and bytes probably(?). I might be missing some conversion of the picture before printing:
FilePageSetupHeader Alignment:=pjLeft, Text:="&P" & UserForm1.Image1.Picture & " "
This prints as: 1-670746914 in the top left header.
What am I missing?
The syntax I found on MSDN gives the following parameters for inserting a picture:
&;P""path"" Inserts the specified image. An example would be &;P"" [My Documents] \Image.gif"". The term [My Documents] represents the full path to your My Documents folder.
My code makes a copy of the current view, make changes to the view settings, headers etc, before exporting to PDF and deleting the view again.
UserForm1.Image1.Picture is a picture object, not the path to the original source file. Once a picture is loaded into an image control, it is embedded and its original path is not stored.
Store the path the the picture so that you can reference it later (e.g. using the Tag property of the Image control). See Stack Overflow: VBA UserForm Get Filename for more details. (FYI: Excel and Project use the same UserForm object, so this is applicable.)
I gave up on saving the logo inside the Project file itself.
Instead I check if the logo exists inside "C:\CompanyLogo", if does not, create that direcotry and download it from imgur.

resize an image stored in a folder

I want to take an image from a folder resize it and store it in the same location with the same name. I saw a lot of examples of how to take an image, resize it and put it inside powerpoint slide but I just want to store it in a folder and not in the presentation. Is that possible?
Use Imagejpeg.
This works to resize a jpeg. It was written to take $content as a feed from a database - just replace with fread() of the iamge you wish to resize.
$newheight=floor($newheight);
$newwidth=floor($newwidth);
$image=imagecreatefromstring($content);
$newimage=imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newimage, $image, 0, 0, 0, 0, $newwidth, $newheight,$row['width'], $row['height']);
imagejpeg($newimage,$filetosaveto);

VB.NET: Preserve image metadata when moved to clipboard as an image

Visual Studio 2010, .NET 4, VB.NET
Hello,
I am writing a little program to convert LaTeX snippets to images which can be pasted into whatever program one can paste images into. It's working alright but the next obvious step is to include the source LaTeX code as a piece of metadata in the image so that the results can be modified without having to retype everything.
I have succeeded in adding a title PropertyItem with the latex encoded as an ASCII byte array as its value (id=800, type=2, value=System.Text.Encoding.ASCII.GetBytes(codestring)). I verify that the PropertyItem is really there before trying to put the image on the clipboard.
Then I do Clipboard.SetImage(myImage). The result is all of the PropertyItems are removed (my title plus anything else that was there)! I check this by doing MsgBox(Clipboard.GetImage.PropertyItems.Count.ToString) which gives zero.
This makes me very sad. Anyone know what's up?
Thanks in advance!
Brian
Update: I have figured out how to move the image onto the clipboard and then back off while preserving the PropertyItems like so:
Format = DataFormats.GetFormat(GetType(Image).FullName)
Dim dataObject As New DataObject
dataObject.SetData(Format.Name, image)
Clipboard.SetDataObject(dataObject)
Dim copiedImage As Image = CType(Clipboard.GetDataObject.GetData(Format.Name), Image)
This way, the copiedImage has the same PropertyItems as the original. However, new problem:
Other programs don't recognize what's on the clipboard as an image anymore, which defeats the whole purpose. I.e., if I put an image on the clipboard this way, when I try pasting into some context that accepts pasted images, nothing happens.
What to do?!
I believe the Windows clipboard image has no metadata. If you change the format of the image to add metadata, it is no longer a clipboard image. If the other programs can accept it, you could copy and paste the image file (instead of the image) to the clipboard, and the metadata will of course be intact when it's read by the target app.
Have you tried Clipboard.SetData or Clipboard.SetDataObject? SetImage only copies the image in bitmap format, so I am not surprised that it strips the property items. You might try:
Clipboard.SetData(DataFormats.EnhancedMetafile, myImage)
or
Clipboard.SetData(DataFormats.MetafilePict, myImage)