? How to get dimensions of gif or jpg 
Author Message
 ? How to get dimensions of gif or jpg

Any advice appreciated.  While it was pointed out to me that I can use
GetBitmapInfoHeader to retrieve the dimensions of a bitmap file, I would
also like to do so for GIFs, JPEGs, and icons.  Can someone suggest the
best method to obtain these values from file headers, or using an API call?
 I am not familiar with the structure/format of these files, and really
don't want to resort to loading the picture into a control and then reading
the control width and height.

Thanks in advance,

Brad Dinerman



Sun, 16 Jul 2000 03:00:00 GMT  
 ? How to get dimensions of gif or jpg


Fri, 19 Jun 1992 00:00:00 GMT  
 ? How to get dimensions of gif or jpg

For icons you can do so by using the GetIconInfo API, which will load an
ICONINFO structure.
Though this required a handle to an icon.
If you'd rather want to get the information straight from an ICO-file,
you'll have to do it yourself, but it's not difficult. Try this:

[declarations section]
Private Type ICONDIR
  idReserved as integer
  idType as integer
  idCount as integer
End Type

Private Type ICONDIRENTRY
  bWidth as byte
  bHeight as byte
  bColorCount as byte
  bReserved as byte
  wPlanes as integer
  wBitCount as integer
  dwBytesinRes as long
  dwImageOffset as long
End Type

Sub GetIconSize(FN as string, hSize(), vSize(), iconcnt%)
  Dim ff As Integer
  Dim id As ICONDIR
  Dim ide As ICONDIRENTRY
  Dim i As Integer
  Dim offset As Long

  ff = FreeFile()
  Open FN For Binary As #ff
    'get offset of first icon's data.
    'This will allow us to calculate how many icons there are
    Seek ff, 19
    Get ff, , offset
    iconcnt% = (offset - 6) / 16
    ReDim hsize(1 To iconcnt%)
    ReDim vsize(1 To iconcnt%)
    Seek ff, 1
    For i = 1 To iconcnt%
      Get ff, , id
      Get ff, , ide
      hsize(i) = ide.bWidth
      vsize(i) = ide.bHeight
    Next i
  Close #ff
End Sub

This simple version will handle several icons in one ICO-file, but has no
error-handling... that's up to you :) :)

However, reading GIFS and JPEGS is a whole lot more complicated. It is
possible, but you'll have to dive into bit- and byte-reversing (certainly
for JPEGS), which is slow in VB. The reaosn for this is that a GIF-file can
come from various systems, including a Mac (has big-endian byte order!).
JPEGS always use big-endian byte order... therefore must always be
reversed.
If you really want to get into it, a very valuable book is "Encyclopedia of
Graphics File Formats" by James D. Murray & William vanRyper, published by
O'Reilly in 1994 (comes with lots of source code in C for reading and
writing all sorts of graphics formats)

Hope this helped!

--
Hans De Schrijver
PUNCTUAL GRAPHICS, Belgium


URL: http://users.skynet.be/PG/index.htm



Any advice appreciated.  While it was pointed out to me that I can use
GetBitmapInfoHeader to retrieve the dimensions of a bitmap file, I would
also like to do so for GIFs, JPEGs, and icons.  Can someone suggest the
best method to obtain these values from file headers, or using an API call?
 I am not familiar with the structure/format of these files, and really
don't want to resort to loading the picture into a control and then reading
the control width and height.

Thanks in advance,

Brad Dinerman
----------



Mon, 17 Jul 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Dimensions of GIF and JPG from files

2. Dimensions of GIF and JPG from files

3. .bmp, .gif, .jpg dimensions

4. Dimensions on gif / jpg

5. Getting size of jpg/gif files

6. Getting the size of a GIF/JPG/PNG?

7. Using VBA in A2k to get dimensions of a jpg file

8. jpg file dimension retrieval

9. Jpg File Dimensions / Html

10. Help! - jpg file dimensions

11. jpg file dimension retrieval

12. Tip: Reading the image dimensions of a GIF file

 

 
Powered by phpBB® Forum Software