日期:2012-04-27  浏览次数:21151 次

网上找的一段代码,把它编译成组件就可以用了,还支持png<br>
<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, bWls