LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

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

admin
2010年7月7日 23:58 本文热度 5663

'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://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


该文章在 2010/7/7 23:58:28 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved