Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image sizes - code for PNG 1

Status
Not open for further replies.

eric43

Programmer
Apr 29, 2005
94
AU
I am using the following routine to find the pixel widths of jpg and bmp files.
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
 
Here is an code sample that will retrieve the info you need on most picture format. This requires "Windows Image Acquisition Automation Library v2.0"


Code:
Img = CreateObject("WIA.ImageFile")
Img.LoadFile (getpic())
s = "Width = " + TRANSFORM(Img.Width) + chr(13) + ;
    "Height = " + TRANSFORM(Img.Height) + chr(13) + ;
    "Depth = " + TRANSFORM(Img.PixelDepth) + chr(13) + ;
    "HorizontalResolution = " + TRANSFORM(Img.HorizontalResolution) + chr(13) + ;
    "VerticalResolution = " + TRANSFORM(Img.VerticalResolution) + chr(13) + ;
    "FrameCount = " + TRANSFORM(Img.FrameCount) + chr(13)
If Img.IsIndexedPixelFormat 
    s = s + "Pixel data contains palette indexes" + chr(13)
EndIf
If Img.IsAlphaPixelFormat
    s = s + "Pixel data has alpha information" + chr(13)
EndIf
If Img.IsExtendedPixelFormat 
    s = s + "Pixel data has extended color information (16 bit/channel)" + chr(13)
EndIf
If Img.IsAnimated 
    s = s + "Image is animated" + chr(13)
EndIf
If Img.Properties.Exists("40091") 
            v = Img.Properties("40091").Value
    s = s + "Title = " + v.String + chr(13)
EndIf
If Img.Properties.Exists("40092") 
            v = Img.Properties("40092").Value
    s = s + "Comment = " + v.String + chr(13)
EndIf
If Img.Properties.Exists("40093") 
            v = Img.Properties("40093").Value
    s = s + "Author = " + v.String + chr(13)
EndIf
If Img.Properties.Exists("40094") 
            v = Img.Properties("40094").Value
    s = s + "Keywords = " + v.String + chr(13)
EndIf
If Img.Properties.Exists("40095") 
            v = Img.Properties("40095").Value
    s = s + "Subject = " + v.String + chr(13)
EndIf
MESSAGEBOX( s)



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top