How to replace image of a picture shape in PowerPoint?

天涯浪子 提交于 2019-12-13 03:34:28

问题


Is there any way to replace the image of an existing picture shape in PowerPoint from code?

Thanks


回答1:


If it's a linked image, either overwrite the linked image file with a new file or point the link at a new file.

Or if the shape is picture filled, you can fill it with a different picture instead. That can distort the picture if its proportions don't match the shape's proportions; instead, you can change the aspect ratio of the shape to match that of the picture if need be.

To change the picture fill, assuming a reference to the shape in osh:

With osh.Fill
    .UserPicture ("C:\path\to\picture.jpg")
End With

To work out the size of the picture so you can adjust the shape to it, you can either use external image processing software or insert the picture into PPT, giving -1 for height and width parameters and pick up the .Height and .Width of the newly inserted picture, then delete it.

Or insert a new picture, pick up the old picture's size/position/other proprties and apply them to the new picture, delete the old picture, move the new one to the old one's Z-order.



来源:https://stackoverflow.com/questions/27022620/how-to-replace-image-of-a-picture-shape-in-powerpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!