Restored from previous forum. Originally posted by tranquil.
Howdy ho, here comes a small procedure wich allows you to get the Width/ Height of a JPG Picture. Have fun. More Filetypes will follow next.

Code: Select all
; Get JPG FileInformations (Width and Height of an Image)
;
; by Tranquilizer/ Secretly!
; Email: mike_delling@web.de
; Someone knows how to find out the Color-Depth???? Please tell me!
; Procedure Returns the Location of the FileHeader containing Fileinformations if everything is okay
; otherwise it returns a negative errorcode
;
; -1 > File could not be opened/ Found
; -2 > Informationheader not Found
; -3 > Not an JPEG File?
;
; imageinfo\width -> X Size
; imageinfo\height -> Y Size
UseJPEG2000ImageDecoder()
Structure my_imageinfo
width.l
height.l
EndStructure
imageinfo.my_imageinfo
Procedure getjpginfo(file$)
Shared imageinfo
If ReadFile(0, file$) <> 0
header1.w = ReadByte(0)
header2.w = ReadByte(0)
header3.w = ReadByte(0)
header4.w = ReadByte(0)
If header1.w = $FF And header2.w = $D8 And header3.w = $FF And header4.w = $E0
finish = 0
Repeat
char.w = ReadByte(0)
If char.w = 255
testchar.w = ReadByte(0)
If testchar.w => $c0 And testchar.w <= $c3
finish = 1
EndIf
EndIf
Until finish = 1 Or Eof(0)
If finish = 1
res = Loc(0): FileSeek(0, res + 3)
imageinfo\height = ReadByte(0) * 256 + ReadByte(0)
imageinfo\width = ReadByte(0) * 256 + ReadByte(0)
Else
res = -2
EndIf
res = -3
EndIf
CloseFile(0)
Else
res = -1
EndIf
ProcedureReturn res
EndProcedure
Tranquilizer/ Secretly!
Registred PureBasic User
Edited by - tranquil on 18 December 2001 02:49:14