网上找的一段代码,把它编译成组件就可以用了,还支持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 youll 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, 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<br>
<br>
<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<br>
<br>
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<br>
<br>
end sub<br>
private function combinebytes(lsb as byte, msb as byte) as long<br>
combinebytes = clng(lsb + (msb * 256))<br>
end function
如何获得jpg文件的实际尺寸呢?
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何获得jpg文件的实际尺寸呢?
相关推荐
-      ASP 简介
-      SQL注入天书 – ASP注入漏洞全接触
-      用.net 处理xmlHttp发送异步请求
-      asp.net创建文件夹的IO类的问题
-      如何实现ASP.NET网站个性化
-      关于ASP.NET调用JavaScript的实现
-      ASP利用Google实现在线翻译功能
-      Asp无组件生成缩略图
