我正在获取一个包含base64编码的XML图像。我要解码那个&需要显示图像。任何建议.............
答案 0 :(得分:1)
cocoawithlove.com上有一个很好的post关于在Mac OS和iPhone上解码base64。
以下是Mac OS创建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];
这适用于iPhone创建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);