Applying new picture to Shape Object


#1

Hi,

I have a Pictureframe on my presentation with a temp image, after locating the relevent shape object I pass it to the function below.

Private Sub ImageReplace(ByRef ImgShp As Shape)
Dim NewImg As Drawing.Bitmap
Dim NewPicId As Integer
'get the picture
NewImg = New Bitmap(MapPath(".") + “/bdrc/bestwestern.png”)
'add the picture to the presentation
With ImgShp.Parent
NewPicId = .Parent.Pictures.Add(New Picture(.Parent, newimg)
End With
'add the reference to the picture
ImgShp.FillFormat.PictureId = NewPicId
End Sub

The idea is to replaced the image with the new one, but I can not get this to work, can you help? I am using VB codebehind…

Thanks,

ZuluWarrior


#2

'add the reference to the picture
ImgShp.FillFormat.Type = FillType.Picture
ImgShp.FillFormat.PictureId = NewPicId


#3

excellent, cheers.

Side node, I managed to solve it a different way, by typecasting the Shape object to a Pictureframe and setting the PictureId from there, eg:

'add the reference to the picture
CType(ImgShp, PictureFrame)PictureId = NewPicId

Just thought I’d post this for completeness and for others…

Regards,

ZuluWarrior