Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to detect the dimension of JPG
Message
De
17/09/2002 04:32:29
 
 
À
13/09/2002 02:42:11
Information générale
Forum:
Visual FoxPro
Catégorie:
Photos et traitement d'images
Divers
Thread ID:
00696132
Message ID:
00701137
Vues:
34
snip

Thank you very much, it give correct data for gif.
And I make modification on jpeg, some of the return value not true but
still give a near width:height ratio for me.

For some images, dimension is 1500:1050, it feedback 112:75 to me.
Fine on ratio up to 1 d.p. :)

Thus, enough for me to rearrange the OleImage in VFP 5.0


>This function will return (hopefully) dimensions of a specified JPEG or GIF file (adapted from Perl, unknow original author):
>
>* usage
>STORE 0 TO x, y
>
>getpictdimensions(getpict(),@x,@y)
>
>? x,y
>
>PROCEDURE GetPictDimensions
>LPARAMETERS cFileName, nWidth, nHeight
>LOCAL lnImg, lnGet
>
>  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

 * remark this EXIT way, usually come at 0xC0 SOF 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
>
>      * if not a jpeg image, go for a gif
>      CASE lcChars = "GI"
>
>        * look for remain gif signal
>        lcChars = FREAD(lnImg,4)
>        IF INLIST(lcChars,"F87a","F89a")
>
>          * it's a GIF file, fetch logical screen size
>          lcChars = FREAD(lnImg,1)
>          nWidth = ASC(lcChars)
>          lcChars = FREAD(lnImg,1)
>          nWidth = nWidth+ASC(lcChars)*256
>
>          lcChars = FREAD(lnImg,1)
>          nHeight = ASC(lcChars)
>          lcChars = FREAD(lnImg,1)
>          nHeight = nHeight+ASC(lcChars)*256
>
>        ENDIF
>
>      ENDCASE
>
>      FCLOSE(lnImg)
>
>    ENDIF
>  ENDIF
>ENDPROC
>
The weak wait for chance, The strong bid for chance,
The clever notch up chance, but The merciful give you chance.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform