vba调用windows image acquisition(wia)库实现给图片添加logo.除了调用vba里面专属的Application.PathSeparator和ThisWorkbook.path,去掉就能给vb6和vbs用了。
代码:
Sub addlogo() Dim logo As Object 'As ImageFile Dim Img As Object 'As ImageFile Dim IP As Object 'As ImageProcess Dim path As String Set Img = CreateObject("WIA.ImageFile") Set logo = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") path = ThisWorkbook.path & Application.PathSeparator Img.LoadFile path & "p01.jpg" logo.LoadFile path & "logo.jpg" IP.Filters.Add IP.FilterInfos("Stamp").FilterID Set IP.Filters(1).Properties("ImageFile") = logo IP.Filters(1).Properties("Left") = (Img.Width - logo.Width) / 2 IP.Filters(1).Properties("Top") = (Img.Height - logo.Height) / 2 Set Img = IP.Apply(Img) Img.SaveFile path & "result.jpg" End Sub
结果:
这个除以2就是放在中间了。去掉2就会放在右下角了。注意一下savefile保存文件在目录存在同名文件的情况下,会出现保存出错的问题,注意这个就好了。