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

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

admin
2010年7月7日 23:58 本文热度 5819
[p]'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. [/p]
[p][br]'check back athttp://qtm.net/~davidc[br]'i may add support for more file types.[/p]
[p]'supported in this version:[br]'jpeg[br]'gif[br]'png[/p]
[p]'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.[/p]
[p]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[/p]
[p]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[/p]
[p]lflen = filelen(sfilename)[br]ifn = freefile[br]open sfilename for binary as ifn[br]get #ifn, 1, btemp()[/p]
[p]'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[/p]
[p]'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, bwlsb[br]get #ifn, 8, bwmsb[br]get #ifn, 9, bhlsb[br]get #ifn, 10, bhmsb[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[/p]
[p][br]'jpeg file[br]if btemp(0) = &hff and btemp(1) = &hd8 and btemp(2) = &hff then[br]debug.print "jpeg"[br]lpos = 3[br]do[br]do[br]get #ifn, lpos, bbuf(1)[br]get #ifn, lpos + 1, bbuf(2)[br]lpos = lpos + 1[br]loop until (bbuf(1) = &hff and bbuf(2) <> &hff) or lpos > lflen[/p]
[p]for icount = 0 to 7[br]get #ifn, lpos + icount, bbuf(icount)[br]next icount[br]if bbuf(0) >= &hc0 and bbuf(0) <= &hc3 then[br]bhmsb = bbuf(4)[br]bhlsb = bbuf(5)[br]bwmsb = bbuf(6)[br]bwlsb = bbuf(7)[br]bdone = 1[br]else[br]lpos = lpos + (combinebytes(bbuf(2), bbuf(1))) + 1[br]end if[br]loop while lpos < lflen and bdone = 0[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]close ifn[/p]
[p]end sub[br]private function combinebytes(lsb as byte, msb as byte) as long[br]combinebytes = clng(lsb + (msb * 256))[br]end function[/p]

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