【源码】修改图片大小

按键精灵小Q 按键精灵小Q 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

作者:昨夜星辰

 

函数名:
SetImageSize 修改图片大小
参数定义:
Path 字符串型:图片文件的完整路径,比如"C:\test.bmp"
Width 整数型:图片宽
Height 整数型:图片高
IsPreserveAspectRatios 布尔型:是否保持图片纵横比,true为保持,false为不保持
Mode 整数型:影响参数Width和Height,0为像素模式,1为百分比模式

返回值:

无


源码:
 

VBSBegin

Function SetImageSize(Path, Width, Height, IsPreserveAspectRatios,Mode)

Dim fso, FileExists_ret

Dim Img,IP

Set fso = CreateObject("Scripting.FileSystemObject")

If (fso.FileExists(path))=true Then

FileExists_ret = 1

Else

FileExists_ret = 0

End If

If FileExists_ret = 1 Then

Set Img = CreateObject("WIA.ImageFile")

Set IP = CreateObject("WIA.ImageProcess")

Img.LoadFile Path

IP.Filters.Add IP.FilterInfos("Scale").FilterID

IP.Filters(1).Properties("PreserveAspectRatio") = IsPreserveAspectRatios

If Mode = 0 Then '像素

IP.Filters(1).Properties("MaximumWidth") = Width

IP.Filters(1).Properties("MaximumHeight") = Height

ElseIf Mode = 1 Then'百分比

IP.Filters(1).Properties("MaximumWidth") = CLng(Img.Width / 100 * Width)

IP.Filters(1).Properties("MaximumHeight") = CLng(Img.Height / 100 * Height)

End If

Set Img = IP.Apply(Img)

fso.DeleteFile Path

Img.SaveFile Path

Set IP = Nothing

Set Img = Nothing

End If

Set fso = Nothing

End Function

VBSEnd

Call SetImageSize("C:\test.bmp", 100, 100, false, 0)'修改图片为100X100,不保持纵横比

原文地址:http://bbs.anjian.com/showtopic-701631-1.aspx

...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
按键精灵小Q
按键精灵小Q 按键精灵官方账号 按键精灵官方账号
按键精灵小Q 11 成员 188 内容