I am trying to create a pptx from a template. The template page is cloned and unique text and pictures need to be loaded on each clone. I am able to replace text on the cloned page. I need to be able to put a unique picture on each page, too. Found other threads that said that this can not be done in pptx. I have not found a way to do it either (replacing the image in a PictureFrameEx).
Does this still not work for pptx? Is there a work around?
I just loaded the latest Slides (March 2010) and still do not see how to do this.
I tried 'Adding Picture Frame to Slide' from the Product Documentation.
It fails at:
Dim img As System.Drawing.Image = CType(New Bitmap("d:\pptx\asp.jpg"), Image)
The Bitmap says the parameter is invalid. I tried a drive path (as shown); I tried a URL; I even tried a local file ("some.jpg"). All of these returned the same error. From what Namespace is the Bitmap in the sample found?
I was going to use this method as a workaround for not being able to just replace the image in a PictureFrameEx. I just keep bumping into walls.
We are sorry for your inconvenience.
I have been able to change the image of the exisiting picture frame. Please have a look on the code snippet provided on this link. This may help you as a possible work around.
Thanks and Regards,
I muddled around and found some code for loading the ImageEx in 217228. I modified that into a routine to load a file, create an ImageEx, and store it in the Presentation:
Public Shared Function loadImageExFromFile(ByVal oPres As PresentationEx, ByVal sFile As String) As ImageEx
Dim oBA() As Byte
Dim oFS As FileStream
Dim oBR As BinaryReader
Dim oMS As MemoryStream
Dim oImg As System.Drawing.Image
Dim oImageEx As ImageEx
Dim iLen As Int32
oFS = New FileStream(sFile, FileMode.Open, FileAccess.Read)
oBR = New BinaryReader(oFS)
iLen = New FileInfo(sFile).Length
oBA = oBR.ReadBytes(iLen)
oMS = New MemoryStream(oBA)
oImg = System.Drawing.Bitmap.FromStream(oMS)
oImageEx = oPres.Images.AddImage(oImg)
From there, I had created a new PictureFrameEx with the ImageEx and deleted the old one. Your line in the referenced link showed me how to changed the image directly in the PictureFrameEx:
oArt = PPTx.loadImageExFromFile(oPres, sFile)
oPic = CType(oSlide.FindShapeByAltText("Art"), PictureFrameEx)
oPic.PictureFormat.Picture.Image = oArt // Your new line replacing the image directly.
Thanks for your help, and I hope this thread will help others solve this problem.