如何获得jpg文件的实际尺寸呢?

2008-04-09 04:13:49来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

网上找的一段代码,把它编译成组件就可以用了,还支持png<br>
<br>
<br>
'I have released this source code into the public domain.&nbsp;&nbsp;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'&nbsp;&nbsp;(see below)<br>
'Return values of 0 indicate an error of some sort.&nbsp;&nbsp;The error handling<br>
'in this module is limited.&nbsp;&nbsp;There is *NO* error handling on the test<br>
'form.&nbsp;&nbsp;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.&nbsp;&nbsp;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>
&nbsp;&nbsp;&nbsp;&nbsp;Width As Long<br>
&nbsp;&nbsp;&nbsp;&nbsp;Height As Long<br>
End Type<br>
<br>
Public Sub GetImageSize(sFileName As String)<br>
&nbsp;&nbsp;&nbsp;&nbsp;On Error Resume Next&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'you'll want to change this<br>
&nbsp;&nbsp;&nbsp;&nbsp;Dim iFN As Integer<br>
&nbsp;&nbsp;&nbsp;&nbsp;Dim bTemp(3) As Byte<br>
&nbsp;&nbsp;&nbsp;&nbsp;Dim lFlen As Long<br>
&nbsp;&nbsp;&nbsp;&nbsp;Dim lPos As Long<br>
&nbsp;&nbsp;&nbsp;&nbsp;Dim bHmsb As Byte<br>
&nbsp;&nbsp;&nbsp;&nbsp;Dim bHlsb As Byte<br>
&nbsp;&nbsp;&nbsp;&nbsp;Dim bWmsb As Byte<br>
&nbsp;&nbsp;&nbsp;&nbsp;Dim bWlsb As Byte<br>
&nbsp;&nbsp;&nbsp;&nbsp;Dim bBuf(7) As Byte<br>
&nbsp;&nbsp;&nbsp;&nbsp;Dim bDone As Byte<br>
&nbsp;&nbsp;&nbsp;&nbsp;Dim iCount As Integer<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;lFlen = FileLen(sFileName)<br>
&nbsp;&nbsp;&nbsp;&nbsp;iFN = FreeFile<br>
&nbsp;&nbsp;&nbsp;&nbsp;Open sFileName For Binary As iFN<br>
&nbsp;&nbsp;&nbsp;&nbsp;Get #iFN, 1, bTemp()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;'PNG file<br>
&nbsp;&nbsp;&nbsp;&nbsp;If bTemp(0) = &H89 And bTemp(1) = &H50 And bTemp(2) = &H4E _<br>
&nbsp;&nbsp;&nbsp;&nbsp;And bTemp(3) = &H47 Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get #iFN, 19, bWmsb<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get #iFN, 20, bWlsb<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get #iFN, 23, bHmsb<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get #iFN, 24, bHlsb<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'GetImageSize.Width = CombineBytes(bWlsb, bWmsb)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'GetImageSize.Height = CombineBytes(bHlsb, bHmsb)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WImg = CombineBytes(bWlsb, bWmsb)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HImg = CombineBytes(bHlsb, bHmsb)<br>
&nbsp;&nbsp;&nbsp;&nbsp;End If<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;'GIF file<br>
&nbsp;&nbsp;&nbsp;&nbsp;If bTemp(0) = &H47 And bTemp(1) = &H49 And bTemp(2) = &H46 _<br>
&nbsp;&nbsp;&nbsp;&nbsp;And bTemp(3) = &H38 Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get #iFN, 7, bWlsb<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get #iFN, 8, bWmsb<br>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:remote script文档(转载自微软)

下一篇:Enterprise Connector messageid 多个SQL 注入漏洞