0
我收到包含圖像是BASE64 encoded.I've器解碼&需要顯示image.Any建議一個XML .............如何從Objective C中的base64編碼字符串讀取圖像?
我收到包含圖像是BASE64 encoded.I've器解碼&需要顯示image.Any建議一個XML .............如何從Objective C中的base64編碼字符串讀取圖像?
有一個不錯的關於在Mac OS和iPhone上解碼base64的cocoawithlove.com上的post。
這裏有一個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);
上獲得的寬度和高度的任何建議? – Heckman 2011-08-15 18:59:00