1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| - (IBAction) trouveLesCouleurs : (id) sender{
NSLog(@"trouveLesCouleurs");
NSSize tailleImage = [uneImage size];
int
pixelsWide = tailleImage.width,
pixelsHigh = tailleImage.height;
NSLog(@"largeur = %d, hauteur = %d", pixelsWide, pixelsHigh);
NSBitmapImageRep *bitmapRep =
[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: nil // Nil pointer makes the kit allocate the pixel buffer for us.
pixelsWide: pixelsWide // The compiler will convert these to integers, but I just wanted to make it quite explicit
pixelsHigh: pixelsHigh //
bitsPerSample: 8
samplesPerPixel: 4 // Four samples, that is: RGBA
hasAlpha: YES
isPlanar: NO // The math can be simpler with planar images, but performance suffers..
colorSpaceName: NSCalibratedRGBColorSpace // A calibrated color space gets us ColorSync for free.
bytesPerRow: 0 // Passing zero means "you figure it out."
bitsPerPixel: 32]; // This must agree with bitsPerSample and samplesPerPixel.
NSInteger i, j;
for(i = 0; i < pixelsWide; i++){
for(j = 0; j < pixelsHigh; j++){
NSColor *uneCouleur = [bitmapRep colorAtX:i y:j];
[couleursFondEcran addObject:uneCouleur];
NSLog(@"i = %d, j = %d, R = %hi, G = %hi", i, j, [uneCouleur redComponent], [uneCouleur greenComponent]);
[uneCouleur release];
}
}
} |
Partager