On Mon, Dec 1, 2008 at 9:46 PM, Dave DeLong <[EMAIL PROTECTED]> wrote: > I've got some NSData objects that I'd like to hard code into a file (they're > encoded images for some example factory methods). The reason I need to hard > code them is that I need to be able to reconstruct these images on both the > Mac and the iPhone, and I thought that getting the TIFFRepresentation of the > 32x32 version and then some how hard coding it into my factory class would > be "simplest". > > If possible, I'd like to avoid compiling in image files, because in the > future I'm planning on being able to accept any image encoded into an NSData > (ones that won't be hard coded), and I'd like to have the built-in presets > follow the same format. > > I've written a little app to take the bytes of an NSData and convert them > into a hexadecimal string, using the code found here: > http://www.cocoabuilder.com/archive/message/cocoa/2007/11/29/194188 , but > I'm at a bit of a loss on how to reconstruct the NSData from the hex string.
Hey, that's me! If you really, truly, honestly have your heart set on this method of image storage (which I think is a bad idea) you want something like this (file)global variable: char imageBytes[] = { 0x00, 0x01, 0xA0, 0x10, ... }; NSUInteger imageBytesLength = 12345; Then you would make it into an NSData again as such: NSData *imageData = [NSData dataWithBytesNoCopy:imageBytes length:imageBytesLength freeWhenDone:NO]; But at that point, it doesn't look much different than the proper, accepted way of doing things (stealing from Jim Correia): NSString *imagePath = [[NSBundle mainBundle] pathForResource: @"MyImage" ofType: @"tiff"]; NSData *imageData = [NSData dataWithContentsOfFile:imagePath]; Really, don't encode it in your binary. Especially bad idea on an embedded platform like the iPhone because they you're carrying around the image data in memory whether you're currently using the image or not. It's dead weight. _______________________________________________ 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]