Codec ░ RGBA

338Accessing RGBA Pixel Data


NSData* pixelData = (NSData*)
	CGDataProviderCopyData(CGImageGetDataProvider(c.CGImage));
unsigned char* pixelBytes = (unsigned char *)[pixelData bytes];
for(int i = 0; i < [pixelData length]; i += 4) {
		NSLog(@"pixelBytes[i] R:%i G:%i B:%i A:%i ",
		(int)pixelBytes[i],
		(int)pixelBytes[i+1],
		(int)pixelBytes[i+2],
		(int)pixelBytes[i+3]);
		/*
		pixelBytes[i] = pixelBytes[i+3];
		pixelBytes[i+1] = pixelBytes[i+3];
		pixelBytes[i+2] = pixelBytes[i+3];
		pixelBytes[i+3] = 0;
		 */
    }
	NSData* newPixelData = [NSData dataWithBytes:pixelBytes length:[pixelData length]];
	UIImage* newImage = [UIImage imageWithData:newPixelData];

361Transparent Background of Custom Drawing Class 347UIImage → pixelData → UIImage Rountrip 334Combining Images with UIImage & CGContext – (Offscreen drawing) 246writeToFile – quick file writing 128Adding Alpha Blending Mode to Quartz Composer