2009-06-05 72 views

回答

1

有一個不錯的關於在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); 
+0

上獲得的寬度和高度的任何建議? – Heckman 2011-08-15 18:59:00