Created
March 16, 2013 15:29
-
-
Save kybernetyk/5176888 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
NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithData:[img TIFFRepresentation]]; | |
int x = [imageRep size].width - 300; | |
int y = 170; | |
float avg = 0.0; | |
float totalcnt = 0; | |
for (int _y = y; _y < y + 120; _y++) { | |
for (int _x = x; _x < x + 270; _x++) { | |
NSColor* color = [imageRep colorAtX: (_x) y: ([imageRep size].height - _y)]; | |
NSColor *rgbColor = [color colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; | |
if (!rgbColor) | |
continue; | |
float avgGray = ([rgbColor redComponent] + [rgbColor greenComponent] + [rgbColor blueComponent]) / 3.0; | |
avg += avgGray; | |
totalcnt += 1.0; | |
[imageRep setColor: [NSColor redColor] atX: _x y: ([imageRep size].height - _y)]; | |
} | |
} | |
// [[imageRep TIFFRepresentation] writeToFile: [tagPath stringByAppendingPathComponent: @"ficken.tiff"] atomically: NO]; | |
float avgGray = avg/totalcnt; | |
NSColor *color = (avgGray >= 0.65) ? [NSColor blackColor] : [NSColor whiteColor]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment