I'm getting a XML containing image which is base64 encoded.I've to decode that & need to display a image.Any suggestions.............
+1
A:
There's a nice post on cocoawithlove.com about decoding base64 on both Mac OS and iPhone.
Here's a Mac OS way to create an NSImage:
unsigned char* data;
int width, height;
NSBitmapImageRep* rep;
rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&data
pixelsWide:width
pixelsHigh:height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bitmapFormat:NSAlphaNonpremultipliedBitmapFormat
bytesPerRow:32
bitsPerPixel:32];
NSImage* image = [[NSImage alloc] initWithSize:NSMakeSize(8, 8)];
[image addRepresentation:rep];
This works on the iPhone to create an UIImage:
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(data, width, height, 8, 32, colorspace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorspace);
CGImageRef cgImage = CGBitmapContextCreateImage(ctx);
CGContextRelease(ctx);
UIImage* image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
Nikolai Ruhe
2009-06-05 10:46:17