I'm building a mobile advertising sdk for the iPhone and I assume that the only way to store the images that will represent the button icons for the landing page controller [in the library] is to convert the images into character arrays.
When I have the character array defined inline like:
const char backButtonData[] = { 0x00, 0x01, 0xFF, ... };
... I can access it like this:
UIImage *backBut开发者_StackOverflow中文版tonImage = [UIImage imageWithData:[NSData dataWithBytesNoCopy:backButtonData length:sizeof(backButtonData) freeWhenDone:NO]];
...and set up the controller's toolbar buttons with these icon images.
I've looked all over hoping to find a script to take image data and spit out a character array but came up empty handed so I've tried myself but have failed miserably.
What I need [hopefully] is a script or function to take the data from:
NSData *imageData = UIImagePNGRepresentation(image);
and spit it out into this format:
0x00, 0x01, 0xFF, ... so I can copy and past it into my source file.
Any ideas [or link to a script or tool that will do this] ?;
I think you really should look into using the UIImage class method +(UIImage*)imageNamed:(NSString *)name
which will load an image file for you.
But if you really want to embed an image file into your app as a char array have a look at the xxd
command line tool and its -i
option.
Thanks a lot epatel, this post also saved me some struggle.
xxd -i
really works great for creating a char array of binary data.
精彩评论