如何获得jpg文件的实际尺寸呢?
2008-04-09 04:13:49来源:互联网 阅读 ()
<br>
<br>
'I have released this source code into the public domain. You may use it<br>
'with no strings attached.<br>
'Just call GetImageSize with a string containing the filename, and<br>
'it will return a user defined type 'ImageSize' (see below)<br>
'Return values of 0 indicate an error of some sort. The error handling<br>
'in this module is limited. There is *NO* error handling on the test<br>
'form. This routine is limited to X or Y sizes of 32767 pixels, but that<br>
'should not be a problem.<br>
<br>
'Check back at http://www.qtm.net/~davidc<br>
'I may add support for more file types.<br>
<br>
'supported in this version:<br>
'JPEG<br>
'GIF<br>
'PNG<br>
<br>
'This routine does not require any royalty fees for Unisys as it<br>
'does nothing with the compressed part of GIF files. It simply reads<br>
'4 bytes to determine image size.<br>
<br>
Option Explicit<br>
Public WImg As Long<br>
Public HImg As Long<br>
Public Type ImageSize<br>
Width As Long<br>
Height As Long<br>
End Type<br>
<br>
Public Sub GetImageSize(sFileName As String)<br>
On Error Resume Next 'you'll want to change this<br>
Dim iFN As Integer<br>
Dim bTemp(3) As Byte<br>
Dim lFlen As Long<br>
Dim lPos As Long<br>
Dim bHmsb As Byte<br>
Dim bHlsb As Byte<br>
Dim bWmsb As Byte<br>
Dim bWlsb As Byte<br>
Dim bBuf(7) As Byte<br>
Dim bDone As Byte<br>
Dim iCount As Integer<br>
<br>
lFlen = FileLen(sFileName)<br>
iFN = FreeFile<br>
Open sFileName For Binary As iFN<br>
Get #iFN, 1, bTemp()<br>
<br>
'PNG file<br>
If bTemp(0) = &H89 And bTemp(1) = &H50 And bTemp(2) = &H4E _<br>
And bTemp(3) = &H47 Then<br>
Get #iFN, 19, bWmsb<br>
Get #iFN, 20, bWlsb<br>
Get #iFN, 23, bHmsb<br>
Get #iFN, 24, bHlsb<br>
'GetImageSize.Width = CombineBytes(bWlsb, bWmsb)<br>
'GetImageSize.Height = CombineBytes(bHlsb, bHmsb)<br>
WImg = CombineBytes(bWlsb, bWmsb)<br>
HImg = CombineBytes(bHlsb, bHmsb)<br>
End If<br>
<br>
'GIF file<br>
If bTemp(0) = &H47 And bTemp(1) = &H49 And bTemp(2) = &H46 _<br>
And bTemp(3) = &H38 Then<br>
Get #iFN, 7, bWlsb<br>
Get #iFN, 8, bWmsb<br>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash