如何遍历NSImage的像素?

需要遍历NSImage的像素并获取每个像素的RGB值,方法如下:

获取RGB值,如下:

CGFloat r,g,b,a;

NSImage* img = ...;

NSBitmapImageRep* imageRep = [NSBitmapImageRep imageRepWithData:[img TIFFRepresentation]];

NSColor* color = [imageRep colorAtX:0 y:0];

[color getRed:&r green:&g blue:&b alpha:&a];

遍历方法

    CGFloat r,g,b,a;

    for(int y = 0; y < imageHeight; ++y) {

        for(int x = 0; x < imageWigth; ++x) {

            NSColor* color = [imageRep colorAtX:x y:y];

            [color getRed:&r green:&g blue:&b alpha:&a];

         }

     }

猜你喜欢

转载自blog.csdn.net/flame_007/article/details/84333803