I need to be able to read an image's dimensions in VB6, but am struggling with the GIF format.
Its easy to do for a bitmap by directly reading the image header part of the file, and can do similar for a JPEG with the help of Intel's JPEG Library.
From code that writes GIF it appears that an image header:
is written to position 783 for an '87 GIF and 791 for an '89 GIF. The code I've written:
doesnt read the correct values.
I can do a workaround by using a control, loadpicture, autosize, scaleheight etc., but that's too slow when working with thousands of images.
Any advice would be really appreciated!
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true." -- Robert Wilensky
Its easy to do for a bitmap by directly reading the image header part of the file, and can do similar for a JPEG with the help of Intel's JPEG Library.
From code that writes GIF it appears that an image header:
Code:
Private Type GifImageDescriptor
Left As Integer
Top As Integer
Width As Integer
Height As Integer
Format As Byte 'ImageFormat
End Type
is written to position 783 for an '87 GIF and 791 for an '89 GIF. The code I've written:
Code:
Private Function GetGIFDimensions(ByVal strGIFFile As String, ByRef intGIFWidth As Integer, ByRef intGIFHeight As Integer) As Boolean
Dim intGFileNo As Integer, strGReadHead As String * 5
On Error GoTo errGetGIFDimensions
intGFileNo = FreeFile
Open strGIFFile For Binary Access Read Lock Read As #intGFileNo
Get #intGFileNo, 1&, strGReadHead
If strGReadHead = "GIF87" Then
Get #intGFileNo, 787&, intGIFWidth
Get #intGFileNo, 789&, intGIFHeight
GetGIFDimensions = True
ElseIf strGReadHead = "GIF89" Then
Get #intGFileNo, 795&, intGIFWidth
Get #intGFileNo, 797&, intGIFHeight
GetGIFDimensions = True
End If
Close #intGFileNo
errGetGIFDimensions:
On Error GoTo 0
Reset
End Function
doesnt read the correct values.
I can do a workaround by using a control, loadpicture, autosize, scaleheight etc., but that's too slow when working with thousands of images.
Any advice would be really appreciated!
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true." -- Robert Wilensky