On 05.08.2008, at 10:03, Wayne Shao wrote:

The imageData method returns NSData*.  Is there anyway to know the
image type (e.g, PNG, TIFF, or JPEG) of the data?


besides that what Ken Ferry wrote you may also use (as I do) a low level
way to determine the image type: check for the magic number of image data.

   const unsigned char *bytes = [imageData bytes];
//NSLog( @"%02x %02x %02x %02x ", bytes[0], bytes[1], bytes[2], bytes[3] );
   BOOL isTIFF_BigEndian = (bytes[0]=='M') && (bytes[1]=='M');
   BOOL isTIFF_LittleEndian = (bytes[0]=='I') && (bytes[1]=='I');
BOOL isJPEG = (bytes[0]==0xff) && (bytes[1]==0xd8) && (bytes[2] ==0xff); BOOL isPNG = (bytes[0]==0x89) && (bytes[1]=='P') && (bytes[2] =='N') && (bytes[3]=='G') && (bytes[4]==0x0d) && (bytes[5]==0x0a) && (bytes[6] ==0x1a) && (bytes[7]==0x0a); BOOL isGIF = (bytes[0]=='G') && (bytes[1]=='I') && (bytes[2] =='F'); BOOL isPDF = (bytes[0]=='%') && (bytes[1]=='P') && (bytes[2] =='D')
                 && (bytes[3]=='F') && (bytes[4]=='-');
   BOOL isBMP     = (bytes[0]=='B') && (bytes[1]=='M');
BOOL isICNS = (bytes[0]=='i') && (bytes[1]=='c') && (bytes[2] =='n') && (bytes[3]=='s');


The Carbon/Cocoa functions and methods do nothing else, they test the magic number.

        Heinrich

--
Heinrich Giesen
[EMAIL PROTECTED]


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to