How do I get the actual size of a JPG file?

Source: Internet
Author: User
Tags error handling integer
Find a piece of code on the Internet, compile it into a component can be used, but also support png<br>
<br>
<br>
' I have released this source code into the public domain. Use it<br>
' With no strings attached.<br>
' Just call getimagesize with a string containing the filename, and<br>
' It'll return a user defined type ' imagesize ' (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 was limited to X or Y sizes of 32767 pixels, but that<br>
' should not to be a problem.<br>
<br>
' Check back at http://www.qtm.net/~davidc<br>
' I may add support for the more file types.<br>
<br>
' Supported in this version:<br>
' Jpeg<br>
' Gif<br>
' Png<br>
<br>
' This routine does is 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 ' I 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<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, bwmsb<br>
Get #iFN, bwlsb<br>
Get #iFN, bhmsb<br>
Get #iFN, 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, bwls



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.