• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: image type of the AdressBook image data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: image type of the AdressBook image data


  • Subject: Re: image type of the AdressBook image data
  • From: Heinrich Giesen <email@hidden>
  • Date: Tue, 5 Aug 2008 11:51:35 +0200


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( @"x x x x ", 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@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: image type of the AdressBook image data
      • From: "Wayne Shao" <email@hidden>
  • Prev by Date: Re: Properties and memory management
  • Next by Date: Re: Properties and memory management
  • Previous by thread: Re: image type of the AdressBook image data
  • Next by thread: Re: image type of the AdressBook image data
  • Index(es):
    • Date
    • Thread