如何獲得jpg檔案的實際尺寸呢?

來源:互聯網
上載者:User
網上找的一段代碼,把它編譯成組件就可以用了,還支援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



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。