0

base64でエンコードされた画像を含むXMLを取得しています。これをデコードして、画像を表示する必要があります。提案があれば............。

4

1 に答える 1

1

cocoawithlove.com に、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);
于 2009-06-05T10:46:17.027 に答える