Created
February 8, 2010 05:17
-
-
Save atr000/297903 to your computer and use it in GitHub Desktop.
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
#import <Foundation/Foundation.h> | |
#import <AppKit/AppKit.h> | |
int main (int argc, const char * argv[]) { | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
if (argc != 4) { | |
printf("Usage: pixelcolor [imgpath] [pixelposx] [pixelposy]\n"); | |
return 1; | |
} | |
[NSApplication sharedApplication]; | |
NSArray *args = [[NSProcessInfo processInfo] arguments]; | |
NSString *filePath = [args objectAtIndex:1]; | |
NSString *stringPosX = [args objectAtIndex:2]; | |
float pixelPosX = [stringPosX floatValue]; | |
NSString *stringPosY = [args objectAtIndex:3]; | |
float pixelPosY = [stringPosY floatValue]; | |
NSImage *img = [[NSImage alloc] initWithContentsOfFile:filePath]; | |
if (img == nil) { | |
printf("Error: Could not load image file.\n"); | |
return 1; | |
} | |
NSPoint point = NSMakePoint(pixelPosX, pixelPosY); | |
[img lockFocus]; | |
NSColor *color = NSReadPixel(point); | |
[img unlockFocus]; | |
[img release]; | |
float red, green, blue, alpha; | |
[color getRed:&red green:&green blue:&blue alpha:&alpha]; | |
printf("%f %f %f %f\n", red, green, blue, alpha); | |
[pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment