How to NSLog pixel RGB from a UIImage?

让人想犯罪 __ 提交于 2019-12-01 09:24:30

Did this direction work for you? I'd get pixel data like this:

UInt32 *pixels = CGBitmapContextGetData( ctx );

#define getRed(p) ((p) & 0x000000FF)
#define getGreen(p) ((p) & 0x0000FF00) >> 8
#define getBlue(p) ((p) & 0x00FF0000) >> 16
// display RGB values from the 11th pixel
NSLog(@"Red: %d, Green: %d, Blue: %d", getRed(pixels[10]), getGreen(pixels[10]), getBlue(pixels[10]));

If you'd like to actually see the image, you can use Florent Pillet's NSLogger: https://github.com/fpillet/NSLogger

The idea is you start the NSLogger client on your desktop, and then in your app you put this up towards the top:

#import "LoggerClient.h"

And in your modifyPixels method you can do something like this:

LogImageData(@"RexOnRoids",        // Any identifier to go along with the log
             0,                    // Log level
             newImage.size.width,  // Image width
             newImage.size.height, // Image height
             UIImagePNGRepresentation(newImage)); // Image as PNG

Start the client on your desktop, and then run the app on your iphone, and you'll see real images appear in the client. VERY handy for debugging image problems such as flipping, rotating, colors, alpha, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!