简体   繁体   English

如何从UIImage NSLog像素RGB?

[英]How to NSLog pixel RGB from a UIImage?

I just want to: 我只想:

1) Copy the pixel data. 1)复制像素数据。
2) Iterate and Modify each pixel (just show me how to NSLog the ARGB values as 255) 2)迭代并修改每个像素(只是告诉我如何将ARGB值NSLog标记为255)
3) Create a UIImage from the new pixel data 3)从新的像素数据创建UIImage

I can figure out the the gory details if someone can just tell me how to NSLog the RGBA values of a pixel as 255. How do I modify the following code to do this? 如果有人可以告诉我如何将像素的RGBA值作为255,我可以弄清楚血腥细节。如何修改以下代码来执行此操作? Be Specific Please! 请具体请!

-(UIImage*)modifyPixels:(UIImage*)originalImage
{

NSData* pixelData = (NSData*)CGDataProviderCopyData(CGImageGetDataProvider(originalImage.CGImage));
uint myLength = [pixelData length];

    for(int i = 0; i < myLength; i += 4) {


        //CHANGE PIXELS HERE
        /*
        Sidenote: Just show me how to NSLog them
        */
        //Example:
        //NSLog(@"Alpha 255-Value is: %u", data[i]);
        //NSLog(@"Red 255-Value is: %u", data[i+1]);
        //NSLog(@"Green 255-Value is: %u", data[i+2]);
        //NSLog(@"Blue 255-Value is: %u", data[i+3]);
    }

    //CREATE NEW UIIMAGE (newImage) HERE 

    return newImage;    
}

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 如果您想真正看到图像,可以使用Florent Pillet的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: 我们的想法是你在桌面上启动NSLogger客户端,然后在你的应用程序中将它放在顶部:

#import "LoggerClient.h"

And in your modifyPixels method you can do something like this: 在您的modifyPixels方法中,您可以执行以下操作:

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. 在桌面上启动客户端,然后在iPhone上运行应用程序,您将看到客户端中显示真实图像。 VERY handy for debugging image problems such as flipping, rotating, colors, alpha, etc. 非常方便调试图像问题,如翻转,旋转,颜色,alpha等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM