2009-06-05 6 views

Répondre

1

Il y a une belle post sur cocoawithlove.com à propos de décodage base64 sur Mac OS et iPhone.

est ici un moyen Mac OS pour créer une 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]; 

Cela fonctionne sur l'iPhone pour créer un 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); 
+0

Les recommandations sur obtenir la largeur et la hauteur? – Heckman

Questions connexes