【源码】修改图片大小

按键精灵小Q
按键精灵官方账号
2022-09-20 13:48:32

作者:昨夜星辰

 

函数名:
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

...全文
199 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

11

社区成员

发帖
与我相关
我的任务
社区描述
按键精灵交流阵地
其他 企业社区
社区管理员
  • 按键精灵小Q
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧