2009-11-26 80 views

回答

3

Like this

而且,看看this question - 第三个答案偏执详细
以及访问像素并将其保存到一个新的UIImage一些代码:从here适应

UIImage* image = ...; // An image 
NSData* pixelData = (NSData*) CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage)); 
void* pixelBytes = [pixelData bytes]; 

//Leaves only the green pixel, assuming 32-bit RGBA 
for(int i = 0; i < [pixelData length]; i += 4) { 
     bytes[i] = 0; // red 
     bytes[i+1] = bytes[i+1]; // green 
     bytes[i+2] = 0; // blue 
     bytes[i+3] = 0; // alpha 
    } 

NSData* newPixelData = [NSData dataWithBytes:pixelBytes length:[pixelData length]]; 
UIImage* newImage = [UIImage imageWithData:newPixelData]; 

。要在不同的图像中显示三个不同的通道,请在代码中进行操作,将每次都要保存的通道设置为零,然后创建新图像。

+0

谢谢,几乎在那里,但这并不表明我如何创建图像。 – SpaceDog 2009-11-26 01:12:11

+0

我需要创建3个图像,每个通道一个,R,G和B,都遵守原始阿尔法。 – SpaceDog 2009-11-26 01:12:49

+0

用新链接编辑... – luvieere 2009-11-26 01:32:46