|
楼主 |
发表于 2024-9-28 22:03
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
你好,运行后,相册图片不见了,没看到添加水印后的图片,不知道是哪里的问题帮我看看,谢谢
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim tm As Double
tm = Timer
Dim WSHShell As Object
Set WSHShell = CreateObject("wscript.shell")
Dim deskPath As String
deskPath = WSHShell.SpecialFolders("Desktop") '也可以自己设置桌面路径
Dim FSO As Object
Set FSO = CreateObject("scripting.Filesystemobject")
Dim p As String, p1 As String
p = deskPath & "\相册" '图片所在位置
p1 = deskPath '水印位置
Dim f As Object
For Each f In FSO.GetFolder(p).Files
On Error Resume Next '避免加载不是图片的错误
Dim strPath As String
strPath = f.Path
Dim 图 As Object, 水印 As Object
Set 图 = CreateObject("WIA.ImageFile")
Set 水印 = CreateObject("WIA.ImageFile")
图.LoadFile strPath
水印.LoadFile p1 & "\水印.png"
Dim 合成图 As Object
Set 合成图 = CreateObject("WIA.ImageProcess")
合成图.Filters.Add 合成图.FilterInfos("stamp").FilterID
Set 合成图.Filters(1).Properties("ImageFile") = 水印
合成图.Filters(1).Properties("Left") = 图.Width - 水印.Width
合成图.Filters(1).Properties("Top") = 水印.Height
Dim 新图 As Object
Set 新图 = 合成图.Apply(图)
FSO.deletefile strPath, True
新图.SaveFile strPath
Next
MsgBox "完毕,共用时: " & Format(Timer - tm, "0.000秒"), , "提示"
Application.ScreenUpdating = True
Application.DisplayAlerts = True |
|