Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load an image stored in a static library

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?

like image 222
zaccox Avatar asked Dec 14 '22 02:12

zaccox


1 Answers

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)

like image 91
rpetrich Avatar answered Dec 24 '22 08:12

rpetrich