提问人:javery 提问时间:9/30/2023 最后编辑:tallerjavery 更新时间:9/30/2023 访问量:42
PowerPoint 在使用 VBA 插入的 .png 图像上留下蓝色背景
PowerPoint Leaving Blue Background on .png Images Inserted With VBA
问:
我有这个插入图像的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 具有透明性,并带有这种丑陋的蓝色填充。当我手动插入同一张图片时,它看起来不错。
我该如何摆脱它?
答:
0赞
taller
9/30/2023
#1
在处理具有透明背景的 PNG 图像时,它来自以下代码:
pic.Fill.Transparency = Rnd() * 0.9
截至目前,尚无可用于使用 VBA 代码管理图像透明度的属性。
该帖子也证实了这一点。
评论
pic.Fill.Transparency = Rnd() * 0.9