Clear
inFile = Getfile("JPG") && 源图像文件名,可以直接指定文件名,比如:inFile = "C:\Temp\MyImageJPG"
outFile = "Temp.Jpg" && 目标图像文件名,可以指定盘符和路径名
lnRatio = 75 && 压缩率,范围:1-100
=Quality(inFile, outFile, lnRatio) && 三个参数,不可缺。
*!* 2. 调整图像质量
Function Quality(inFile As Character, outFile As Character, lnRatio As Integer)
Local Img && As ImageFile
Local IP && As ImageProcess
Img = Createobject("WIA.ImageFile")
IP = Createobject("WIA.ImageProcess")
Img.LoadFile(inFile)
*!* 压缩/调整质量:
IP.Filters.Add(IP.FilterInfos("Convert").FilterID)
IP.Filters(1).Properties("FormatID").Value = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}" && JPG 文件格式
IP.Filters(1).Properties("Quality").Value = lnRatio
Img = IP.Apply(Img)
Delete File &outFile
Img.SaveFile(outFile)
*!* 比较调整前后的文件大小
=Adir(gaJPG, inFile)
? "调整前的文件大小 : " + Transform(gaJPG(2)/1024) + "KB"
=Adir(gaJPG, outFile)
? "调整后的文件大小 : " + Transform(gaJPG(2)/1024) + "KB"
? "完成."
Endfunc