2009-06-05 7 views

Antwort

1

Es gibt einen schönen post auf cocoawithlove.com über die Decodierung von Base64 auf Mac OS und iPhone.

Hier ist ein Mac OS Weg, um eine NSImage zu erstellen:

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]; 

Diese auf dem iPhone funktioniert eine UIImage zu erstellen:

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); 
+0

Alle Empfehlungen auf die Breite und Höhe zu bekommen? – Heckman