vbscript如何获得系统图片文件的像素大小

leohyf 2010-03-30 10:46:19
如题。
可以直接获取到像素吗?
用picture对象返回的值单位是twip~
...全文
103 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
leohyf 2010-04-01
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 microogle 的回复:]
第一种比例不是固定,获取不得绝对准确的值;

第三种如果是jpg格式读几字节呢?
Microogle 2010-04-01
  • 打赏
  • 举报
回复
1.
Dim sFile,str
sFile = "a.bmp"
Set oPicture = LoadPicture(sFile)
str = "文件:" & vbTab & sFile & vbCrLf
str = str & "宽度:" & vbTab & Fix(oPicture.Width / 26.458) & vbCrLf
str = str & "高度:" & vbTab & Fix(oPicture.Height / 26.458)
Set oPicture = Nothing
WScript.Echo str
2.
Dim arrFile
Dim oFile,oDir,oShell

arrFile = MyGetFile()
Set oShell = CreateObject("Shell.Application")
Set oDir = oShell.NameSpace(arrFile(1) + "\")
Set oFile = oDir.ParseName(arrFile(0))
WScript.Echo oDir.GetDetailsOf(oFile,-1)

Set oFile = Nothing
Set oDir = Nothing
Set oShell = Nothing

'***********************************************************************************
'获得要操作的文件,返回一个包含文件名和路径的数组
'***********************************************************************************
Function MyGetFile()

On Error Resume Next
Dim strFile,objFso,objFile
If WScript.Arguments.Count < 1 Then
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "bmp 文件|*.bmp|jpg 文件|*.jpg|ico 文件|*.ico|所有 文件|*.*"
objDialog.ShowOpen
strFile = objDialog.FileName
Set objDialog = Nothing
Else
strFile = WScript.Arguments(0)
end if
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFile = objFso.GetFile(strFile)
If Err Then
If Err.Number = 5 Then WScript.Quit
WScript.Echo Err.Description
Err.Clear
WScript.Quit
Else
MyGetFile = Array(objFile.Name,objFile.ParentFolder)
End If

Set objFile = Nothing
Set objFso = Nothing

End Function

3.
Dim sFile,str
Dim oStream
Dim bWidth,bHeight

sFile = "a.bmp"
Set oStream = CreateObject("Adodb.Stream")
With oStream
.Type = 1
.Open
.LoadFromFile sFile
End With

'如果是BMP格式,则Position=18,读4字节;
'如果是gif格式,则为Position=6,读2字节;
'如果是png格式,则Position=16,读4字节
oStream.Position = 18
bWidth = oStream.Read(4)
bHeight = oStream.Read(4)
oStream.Close

str = "文件:" & vbTab & sFile & vbCrLf
str = str & "宽度:" & vbTab & Bin2Num(bWidth) & vbCrLf
str = str & "高度:" & vbTab & Bin2Num(bHeight)
Set oStream = Nothing
WScript.Echo str

'二进制流转换为数值
Function Bin2Num(binStr)

Dim i,numLen
numLen = Lenb(binStr)
For i = numLen To 1 Step -1
Bin2Num = Bin2Num * 256 + Ascb(Midb(binStr,i,1))
Next

End Function

很久以前写的了。
liguicd 2010-03-31
  • 打赏
  • 举报
回复
帮顶....

4,008

社区成员

发帖
与我相关
我的任务
社区描述
它是一种微软环境下的轻量级的解释型语言,它使用COM组件、WMI、WSH、ADSI访问系统中的元素,对系统进行管理。
社区管理员
  • vbScript社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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