Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.