如何遍歷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];

         }

     }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章