Given:
unsigned char *myImageData;
NSUInteger myImageDataLength;
Where myImageData
is the image in JPEG, PNG or some other UIImage supported format, use:
-(UIImage*)myImage {
return [UIImage imageWithData:[NSData dataWithBytes:myImageData length:myImageDataLength]];
}
If your char data is Base64 encoded, check out http://www.cocoadev.com/index.pl?BaseSixtyFour.
I've done this both with data from a web service and to bake-in an image. For example:
// Note hex = ".PNG..", the start of the PNG header.
static unsigned char myImageData[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a,... };
The length is the image file size, and the hex values can be created from the image file with:
hexdump -e ' 16/1 "0x%02x, " "\n"' MyImage.png