一个取图片尺寸的类,支持jpg,gif,png

原创 2004年09月18日 22:47:00
'I have released this source code into the public domain. You may use it
'with no strings attached.
'Just call GetImageSize with a string containing the filename, and
'it will return a user defined type 'ImageSize' (see below)
'Return values of 0 indicate an error of some sort. The error handling
'in this module is limited. There is *NO* error handling on the test
'form. This routine is limited to X or Y sizes of 32767 pixels, but that
'should not be a problem.

'Check back athttp://www.qtm.net/~davidc
'I may add support for more file types.

'supported in this version:
'JPEG
'GIF
'PNG

'This routine does not require any royalty fees for Unisys as it
'does nothing with the compressed part of GIF files. It simply reads
'4 bytes to determine image size.

Option Explicit
Public WImg As Long
Public HImg As Long
Public Type ImageSize
Width As Long
Height As Long
End Type

Public Sub GetImageSize(sFileName As String)
On Error Resume Next 'you'll want to change this
Dim iFN As Integer
Dim bTemp(3) As Byte
Dim lFlen As Long
Dim lPos As Long
Dim bHmsb As Byte
Dim bHlsb As Byte
Dim bWmsb As Byte
Dim bWlsb As Byte
Dim bBuf(7) As Byte
Dim bDone As Byte
Dim iCount As Integer

lFlen = FileLen(sFileName)
iFN = FreeFile
Open sFileName For Binary As iFN
Get #iFN, 1, bTemp()

'PNG file
If bTemp(0) = &H89 And bTemp(1) = &H50 And bTemp(2) = &H4E _
And bTemp(3) = &H47 Then
Get #iFN, 19, bWmsb
Get #iFN, 20, bWlsb
Get #iFN, 23, bHmsb
Get #iFN, 24, bHlsb
'GetImageSize.Width = CombineBytes(bWlsb, bWmsb)
'GetImageSize.Height = CombineBytes(bHlsb, bHmsb)
WImg = CombineBytes(bWlsb, bWmsb)
HImg = CombineBytes(bHlsb, bHmsb)
End If

'GIF file
If bTemp(0) = &H47 And bTemp(1) = &H49 And bTemp(2) = &H46 _
And bTemp(3) = &H38 Then
Get #iFN, 7, bWlsb
Get #iFN, 8, bWmsb
Get #iFN, 9, bHlsb
Get #iFN, 10, bHmsb
'GetImageSize.Width = CombineBytes(bWlsb, bWmsb)
'GetImageSize.Height = CombineBytes(bHlsb, bHmsb)
WImg = CombineBytes(bWlsb, bWmsb)
HImg = CombineBytes(bHlsb, bHmsb)
End If


'JPEG file
If bTemp(0) = &HFF And bTemp(1) = &HD8 And bTemp(2) = &HFF Then
Debug.Print "JPEG"
lPos = 3
Do
Do
Get #iFN, lPos, bBuf(1)
Get #iFN, lPos + 1, bBuf(2)
lPos = lPos + 1
Loop Until (bBuf(1) = &HFF And bBuf(2) <> &HFF) Or lPos > lFlen

For iCount = 0 To 7
Get #iFN, lPos + iCount, bBuf(iCount)
Next iCount
If bBuf(0) >= &HC0 And bBuf(0) <= &HC3 Then
bHmsb = bBuf(4)
bHlsb = bBuf(5)
bWmsb = bBuf(6)
bWlsb = bBuf(7)
bDone = 1
Else
lPos = lPos + (CombineBytes(bBuf(2), bBuf(1))) + 1
End If
Loop While lPos < lFlen And bDone = 0
'GetImageSize.Width = CombineBytes(bWlsb, bWmsb)
'GetImageSize.Height = CombineBytes(bHlsb, bHmsb)
WImg = CombineBytes(bWlsb, bWmsb)
HImg = CombineBytes(bHlsb, bHmsb)
End If
Close iFN

End Sub
Private Function CombineBytes(lsb As Byte, msb As Byte) As Long
CombineBytes = CLng(lsb + (msb * 256))
End Function

(出处:动网论坛)

java web - 限制文件的上传类型为图片类型(.gif,.png,.jpg,.jpeg)

1.使用ajax function insertTitle(tValue){ if(tValue!=''){ var len = tValue.length; var str = tValue....
  • qq_31420401
  • qq_31420401
  • 2016年10月10日 14:43
  • 1342

img、png、gif图片区别详细辨析

之前做笔记的时候,觉得说的自己不理解明白,所以问了下,也大概清楚了。 三种图片格式区别大概是这样的: PNG JPG GIF 质量 png-24质量最好 png-8相对24的较...
  • huangyibin628
  • huangyibin628
  • 2014年03月13日 20:49
  • 2467

Gif,png,jpg,webp几种图片格式整理

gif,png,jpg,webp图片格式详解
  • playboyanta123
  • playboyanta123
  • 2015年03月26日 20:51
  • 6667

图片裁剪工具类(支持jpg,png,bmp,gif(剪切后为静态))

package com.util; import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.io.F...
  • qq183518918
  • qq183518918
  • 2013年11月15日 12:51
  • 1630

可以调整gif动画图片尺寸的很实用的php类

类的使用demo: php //http://www.cnblogs.com/roucheng/ require_once "roucheng.php"; $gr = new gifr...
  • u012443816
  • u012443816
  • 2013年12月06日 06:40
  • 588

利用win32 GDI+ 修改图片格式和尺寸(支持jpg png bmp)

  • 2017年08月08日 11:48
  • 109KB
  • 下载

(AutoIt 实例)图片批量重命名小工具,支持jpg、jpeg、png、gif格式

近来无聊写的,用时要先把软件放在图片目录,设置好名字,然后点击立即执行,图片会以 你设置的名字 + 数字 把图片重命名。简单易用。 目前只支持jpg、jpeg、png、gif格式,若想支持更多格式,...
  • skywn
  • skywn
  • 2012年08月23日 20:16
  • 1441

java将图片缩放实现类(能将jpg、bmp、png、gif图片文件,进行等比或非等比的大小转换)

/** * 缩略图实现,将图片(jpg、bmp、png、gif等等)真实的变成想要的大小 */ package com.joewalker.test; impo...
  • alongshow
  • alongshow
  • 2012年04月13日 16:33
  • 2013

GIF Resizer - 调整GIF动画图片尺寸大小的免费小工具.qiweb

  • 2012年09月04日 22:09
  • 525KB
  • 下载

gif修改,分解,合成软件 修改gif图片尺寸而不失动态

  • 2010年08月14日 12:00
  • 331KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:一个取图片尺寸的类,支持jpg,gif,png
举报原因:
原因补充:

(最多只允许输入30个字)