這是好久以前編寫的代碼,該代碼是讀取流數據指定位置的內容,獲取圖片的寬度、高度值。函數
因爲系統更新,這些代碼丟之不用,在這裏存個檔吧!oop
1. 獲取gif圖片寬度、高度。(binary_是圖片流數據)spa
'*************************** ' 函數: gif_size() ' 說明: 獲取gif的寬高值 ' 返回: [Array] ' Array(0) 寬度值 ' Array(1) 高度值 ' Private Function gif_size() On Error Resume Next Dim w, h w = sysString.hexToOct( hex(ascb(midb(binary_,8,1))) & hex(ascb(midb(binary_,7,1))) ) h = sysString.hexToOct( hex(ascb(midb(binary_,10,1))) & hex(ascb(midb(binary_,9,1))) ) If Err.Number<>0 Then gif_size = Array(0,0) Err.Clear() Else If sysNumber.isInt(w, 1) And sysNumber.isInt(h, 1) Then gif_size = Array(w, h) Else gif_size = Array(0,0) End If End If End Function
2. 獲取jpg圖片寬度、高度。(binary_是圖片流數據)code
'*************************** ' 函數: jpg_size() ' 說明: 獲取jpg的寬高值 ' 返回: [Array] ' Array(0) 寬度值 ' Array(1) 高度值 ' Private Function jpg_size() On Error Resume Next Dim w, h Dim splitStr, i, tmp_binary 'FF 的ASC值爲 255 C0 的ASC值爲 192 'split是沒法將流進行分割,但instrb能夠獲取標識所在的位置點 '因爲有些圖片含有多個ff c0標識,但最後一個纔是最終的標識,因此採用反覆不停過濾掉ff c0方式 tmp_binary = binary_ splitStr = chrb(255) & chrb(192) i = instrb(tmp_binary, splitStr) Do While i<>0 w = sysString.hexToOct( hex(ascb(midb(tmp_binary,i+7,1))) & hex(ascb(midb(tmp_binary,i+8,1))) )'寬 h = sysString.hexToOct( hex(ascb(midb(tmp_binary,i+5,1))) & hex(ascb(midb(tmp_binary,i+6,1))) )'高 tmp_binary = midb(tmp_binary,i+2) i = instrb(tmp_binary, splitStr) Loop If Err.Number<>0 Then jpg_size = Array(0,0) Err.Clear() Else If sysNumber.isInt(w, 1) And sysNumber.isInt(h, 1) Then jpg_size = Array(w, h) Else jpg_size = Array(0,0) End If End If End Function
3. 獲取png圖片寬度、高度。(binary_是圖片流數據)blog
'*************************** ' 函數: jpg_size() ' 說明: 獲取jpg的寬高值 ' 返回: [Array] ' Array(0) 寬度值 ' Array(1) 高度值 ' Private Function png_size() On Error Resume Next Dim w, h w = sysString.hexToOct( hex(ascb(midb(binary_,17,1))) & hex(ascb(midb(binary_,18,1))) & hex(ascb(midb(binary_,19,1))) & hex(ascb(midb(binary_,20,1))) ) h = sysString.hexToOct( hex(ascb(midb(binary_,21,1))) & hex(ascb(midb(binary_,22,1))) & hex(ascb(midb(binary_,23,1))) & hex(ascb(midb(binary_,24,1))) )'高 If Err.Number<>0 Then png_size = Array(0,0) Err.Clear() Else If sysNumber.isInt(w, 1) And sysNumber.isInt(h, 1) Then png_size = Array(w, h) Else png_size = Array(0,0) End If End If End Function