Created
February 21, 2013 00:59
-
-
Save C4Code/5001069 to your computer and use it in GitHub Desktop.
Working with Raw Pixels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // C4WorkSpace.m | |
| // | |
| // Created by Travis Kirton | |
| // | |
| #import "C4WorkSpace.h" | |
| @implementation C4WorkSpace | |
| -(void)setup { | |
| [self getRawPixelsAndCreateImages]; | |
| } | |
| -(void)getRawPixelsAndCreateImages { | |
| C4Image *image = [C4Image imageNamed:@"C4Table.png"]; | |
| NSUInteger width = CGImageGetWidth(image.CGImage); | |
| NSUInteger height = CGImageGetHeight(image.CGImage); | |
| CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
| NSUInteger bytesPerPixel = 4; | |
| NSUInteger bytesPerRow = bytesPerPixel * width; | |
| unsigned char *rawData = malloc(height * bytesPerRow); | |
| NSUInteger bitsPerComponent = 8; | |
| CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); | |
| CGColorSpaceRelease(colorSpace); | |
| CGContextDrawImage(context, CGRectMake(0, 0, width, height), image.CGImage); | |
| CGContextRelease(context); | |
| C4Image *imgimgimg = [[C4Image alloc] initWithRawData:rawData width:width height:height]; | |
| [self.canvas addImage:imgimgimg]; | |
| for(int i = 0; i < height * bytesPerRow; i += 4) { | |
| rawData[i] = 255; | |
| } | |
| C4Image *redImgimgimg = [[C4Image alloc] initWithRawData:rawData width:width height:height]; | |
| redImgimgimg.origin = CGPointMake(0,320); | |
| [self.canvas addImage:redImgimgimg]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment