Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Most efficient way to get the pixel dimensions of a JPG
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Most efficient way to get the pixel dimensions of a JPG



John,

You can just read the dimensions in the header of the JPEG file. No need to decode the pixels. The format is available many places, like here:

http://netghost.narod.ru/gff/graphics/summary/jfif.htm


typedef struct _JFIFHeader { BYTE SOI[2]; /* 00h Start of Image Marker */ BYTE APP0[2]; /* 02h Application Use Marker */ BYTE Length[2]; /* 04h Length of APP0 Field */ BYTE Identifier[5]; /* 06h "JFIF" (zero terminated) Id String */ BYTE Version[2]; /* 07h JFIF Format Revision */ BYTE Units; /* 09h Units used for Resolution */ BYTE Xdensity[2]; /* 0Ah Horizontal Resolution */ BYTE Ydensity[2]; /* 0Ch Vertical Resolution */ BYTE XThumbnail; /* 0Eh Horizontal Pixel Count */ BYTE YThumbnail; /* 0Fh Vertical Pixel Count */ } JFIFHEAD;

So, read sizeof(JFIFHEAD) from the start of the file.

-jcr

On Jan 6, 2005, at 3:46 PM, John Fox wrote:


Hello:

I'm looking for a really fast and memory efficient way to determine the pixel height and width of a JPEG image. Can someone help me with this? Right now I'm creating an NSBitmapImageRep and getting its pixelsWide and pixelsHigh, but there's a lot of overhead for doing this.

Any help greatly appreciated.


John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Most efficient way to get the pixel dimensions of a JPG (From: John Fox <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.