当前位置: 代码迷 >> vbScript >> vbscript怎么获得系统图片文件的像素大小
  详细解决方案

vbscript怎么获得系统图片文件的像素大小

热度:9904   发布时间:2013-02-26 00:00:00.0
vbscript如何获得系统图片文件的像素大小
如题。
可以直接获取到像素吗? 
用picture对象返回的值单位是twip~ 


------解决方案--------------------------------------------------------
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

很久以前写的了。
  相关解决方案