
? 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
----------