in my iphone app, I am linking with a static library containing objective c files and images. Is it possible to load an image from a static library? I have tried
[UIImage imageNamed:[[NSBundle mainBundle] pathForResource:@"imageName" ofType:@"png"]];
but obviously the image is not in the main bundle, it's in the static library and the NSBundle class seems only to offer access to the main bundle and to bundles with known paths. Is there a way to load an image from a static library on the iPhone?
The simplest way is to store the image in an inline character array:
const char imageData[] = { 0x00, 0x01, 0xFF, ... };
And later when you need it:
UIImage *image = [UIImage imageWithData:[NSData dataWithBytesNoCopy:imageData length:sizeof(imageData) freeWhenDone:NO]];
You will have to convert your image's binary data (after saved as either PNG or JPEG) to the character array manually (or write a script to do so)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With