I am using the following routine to find the pixel widths of jpg and bmp files.
Can anyone point me to similar routines for PNG and GIF files?
Eric
Code:
PROCEDURE GetPictDimensions
LPARAMETERS cFileName
LOCAL lnImg, lnGet, nWidth, nHeight,fulldetails
STORE -1 TO nWidth, nHeight
* try to open picture file
IF FILE(cFileName)
lnImg = FOPEN(cFileName,10)
IF lnImg>=0
* successfully opened, so get first two bytes
lcChars = FREAD(lnImg,2)
DO CASE
* 0xFFD8 signals a jpeg image
CASE lcChars = CHR(0xFF)+CHR(0xD8)
* fetch next marker
DO WHILE !FEOF(lnImg)
lcChars = FREAD(lnImg,1)
* found a marker
IF lcChars=CHR(0xFF)
* must discard extra 0xFFs
DO WHILE lcChars=CHR(0xFF)
lcChars = FREAD(lnImg,1)
ENDDO
* is this the SOF marker?
IF BETWEEN(ASC(lcChars),0xC0,0xC3)
FREAD(lnImg,3)
* read dimensions
lcChars = FREAD(lnImg,1)
nHeight = ASC(lcChars)*256
lcChars = FREAD(lnImg,1)
nHeight = nHeight+ASC(lcChars)
lcChars = FREAD(lnImg,1)
nWidth = ASC(lcChars)*256
lcChars = FREAD(lnImg,1)
nWidth = nWidth+ASC(lcChars)
EXIT
* if not, jump to the next marker
ELSE
* get the offset
lcChars = FREAD(lnImg,1)
lnOffset = ASC(lcChars)*256
lcChars = FREAD(lnImg,1)
lnOffset = lnOffset+ASC(lcChars)
* go ahead to next marker
IF lnOffset>2
FSEEK(lnImg,lnOffset-2,1)
ELSE
EXIT
ENDIF
ENDIF
ENDIF
ENDDO
Can anyone point me to similar routines for PNG and GIF files?
Eric