PowerPoint 在使用 VBA 插入的 .png 图像上留下蓝色背景

问题描述 投票:0回答:1

我有一个插入图像的 powerpoint 宏片段:

Sub InsertRandomPictures()
    Dim fso As Object
    Dim folder As Object
    Dim file As Object
    Dim pptSlide As Slide
    Dim pic As shape
    Dim folderPath As String
    Dim randomWidth As Single, randomHeight As Single
    Dim aspectRatio As Single
    Dim tempPic As shape
    Dim counter As Integer
    
    ' Set the path to the folder containing the pictures
    folderPath = "my/path/to/folder"
    
    ' Set up FileSystemObject
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder = fso.GetFolder(folderPath)
    
    ' Reference slide 2
    Set pptSlide = ActivePresentation.Slides(2)
    
    ' Loop through each file in the folder
    For Each file In folder.Files
        ' Check if the file is a picture by looking at its extension
        If LCase(Right(file.Name, 3)) = "jpg" Or LCase(Right(file.Name, 3)) = "png" Or LCase(Right(file.Name, 3)) = "gif" Then        
            
            ' Insert the picture onto slide 2
            Set pic = pptSlide.Shapes.AddPicture( _
                fileName:=folderPath & file.Name, _
                LinkToFile:=msoFalse, _
                SaveWithDocument:=msoTrue, _
                Width:= 100, _
                Height:= 100)
                
            ' Set a random transparency value
            pic.Fill.Transparency = Rnd() * 0.9         
        End If
    Next file
End Sub

但是,它使我的 .png 图像和 .gif 带有丑陋的蓝色填充的透明度。当我手动插入同一张图片时,看起来不错。

(see picture)

我该如何摆脱这个?

vba image powerpoint
1个回答
0
投票

在处理具有透明背景的PNG图像时,它来自以下代码:

pic.Fill.Transparency = Rnd() * 0.9

到目前为止,还没有可用于使用 VBA 代码管理图像透明度的属性。

帖子也证实了这一点。

PowerPoint VBA 中的图片透明度对象

© www.soinside.com 2019 - 2024. All rights reserved.