函数名:GetImageSize_PictureBox参数定义:
FileName 字符串型:图片完整路径返回值:
整数型数组:下标0为图片宽,下标1为图片高。
调用例子:
TracePrint Join(GetImageSize_PictureBox("C:\1.bmp"))
TracePrint Join(GetImageSize_PictureBox("C:\1.jpg"))
TracePrint Join(GetImageSize_PictureBox("C:\1.gif"))
'需要提前在QUI中创建一个名为“PictureBox1”的图像控件,仅支持bmp、jpg、gif格式。
源码:
- Function GetImageSize_PictureBox(FileName)
- GetImageSize_PictureBox = Array(0, 0)
- Form1.PictureBox1.Picture = FileName
- GetImageSize_PictureBox = Array(Form1.PictureBox1.Width, Form1.PictureBox1.Height)
- End Function
复制代码
函数名:
GetImageSize_LoadFile
参数定义:
FileName 字符串型:图片完整路径
返回值:
整数型数组:下标0为图片宽,下标1为图片高。
调用例子:
TracePrint Join(GetImageSize_LoadFile("C:\1.bmp"))
TracePrint Join(GetImageSize_LoadFile("C:\1.png"))
TracePrint Join(GetImageSize_LoadFile("C:\1.jpg"))
TracePrint Join(GetImageSize_LoadFile("C:\1.gif"))
'支持bmp、png、jpg、gif等格式。
源码:
- Function GetImageSize_LoadFile(FileName)
- GetImageSize_LoadFile = Array(0, 0)
- Dim Img
- Set Img = CreateObject("WIA.ImageFile")
- Img.LoadFile FileName
- GetImageSize_LoadFile = Array(Img.Width, Img.Height)
- Set Img = Nothing
- End Function
复制代码
函数名:
GetImageSize_LoadPicture
参数定义:
FileName 字符串型:图片完整路径
返回值:
整数型数组:下标0为图片宽,下标1为图片高。
调用例子:
TracePrint Join(GetImageSize_LoadPicture("C:\1.bmp"))
TracePrint Join(GetImageSize_LoadPicture("C:\1.jpg"))
TracePrint Join(GetImageSize_LoadPicture("C:\1.gif"))
'仅支持bmp、jpg、gif格式。
源码:
- Function GetImageSize_LoadPicture(FileName)
- GetImageSize_LoadPicture = Array(0, 0)
- Dim key
- key = "HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI"
- Dim WshShell, dpi
- Set WshShell = CreateObject("Wscript.Shell")
- dpi = WshShell.RegRead(key)
- Set WshShell = Nothing
- Dim p
- Set p = LoadPicture(FileName)
- GetImageSize_LoadPicture = Array(Round(p.Width * dpi / 2540), Round(p.Height * dpi / 2540))
- Set p = Nothing
- End Function
复制代码
函数名:
GetImageSize_Binary
参数定义:
FileName 字符串型:图片完整路径
返回值:
整数型数组:下标0为图片宽,下标1为图片高。
调用例子:
TracePrint Join(GetImageSize_Binary("C:\1.bmp"))
TracePrint Join(GetImageSize_Binary("C:\1.png"))
TracePrint Join(GetImageSize_Binary("C:\1.jpg"))
TracePrint Join(GetImageSize_Binary("C:\1.gif"))
'仅支持bmp、png、jpg、gif格式。
源码:
- TracePrint Join(GetImageSize_Binary("C:\1.bmp"))
- TracePrint Join(GetImageSize_Binary("C:\1.png"))
- TracePrint Join(GetImageSize_Binary("C:\1.jpg"))
- TracePrint Join(GetImageSize_Binary("C:\1.gif"))
- Function GetImageSize_Binary(FileName)
- GetImageSize_Binary = Array(0, 0)
- Dim Adodb, i, UBound_Buf, Bin
- Set Adodb = CreateObject("Adodb.Stream")
- Adodb.mode = 3
- Adodb.type = 1
- Adodb.Open
- Adodb.LoadFromFile FileName
- UBound_Buf = Adodb.Size - 1
- If UBound_Buf > 166 Then
- UBound_Buf = 166
- End If
- Redim Buf(UBound_Buf)
- For i = 0 To UBound_Buf
- Buf(i) = AscB(Adodb.Read(1))
- Next
- Adodb.Close
- Set Adodb = Nothing
- Bin = buf
- If UBound(Bin) = - 1 Then
- GetImageSize_Binary = Array(0, 0)
- Exit Function
- End If
- Dim info, w, h
- w = ""
- h = ""
- info = ""
- For i = 0 To 1
- info = info & Hex(Bin(i))
- Next
- If info = "FFD8" Then //JPG
- For i = 165 To 166
- w = w & Hex(Bin(i))
- Next
- For i = 163 To 164
- h = h & Hex(Bin(i))
- Next
- GetImageSize_Binary = Array(Abs(Eval("&H" & w)), Abs(Eval("&H" & h)))
- Exit Function
- End If
- info = ""
- For i = 0 To 1
- info = info & Hex(Bin(i))
- Next
- If info = "424D" Then //BMP
- For i = 19 To 18 Step - 1
- w = w & Hex(Bin(i))
- Next
- For i = 23 To 22 Step - 1
- h = h & Hex(Bin(i))
- Next
- GetImageSize_Binary = Array(Abs(Eval("&H" & w)), Abs(Eval("&H" & h)))
- Exit Function
- End If
- info = ""
- For i = 0 To 3
- info = info & Hex(Bin(i))
- Next
- If info = "89504E47" Then //PNG
- For i = 18 To 19
- w = w & Hex(Bin(i))
- Next
- For i = 22 To 23
- h = h & Hex(Bin(i))
- Next
- GetImageSize_Binary = Array(Abs(Eval("&H" & w)), Abs(Eval("&H" & h)))
- Exit Function
- End If
- info = ""
- For i = 0 To 2
- info = info & Hex(Bin(i))
- Next
- If info = "474946" Then //GIF
- For i = 7 To 6 step -1
- w = w & Hex(Bin(i))
- Next
- For i = 9 To 8 step -1
- h = h & Hex(Bin(i))
- Next
- GetImageSize_Binary = Array(Abs(Eval("&H" & w)), Abs(Eval("&H" & h)))
- Exit Function
- End If
- End Function
复制代码