How to NSLog RGB pixel from UIImage?

I just want to:

1) Copy the pixel data.
2) Iterate and modify each pixel (just show me how NSLog has ARGB values ​​like 255)
3) Create a UIImage from the new pixel data

I can figure out the details of gory if someone can just tell me how NSLog pixel values ​​are RGBA as 255. How can I change the following code to do this? Be specific!

-(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;    
}
+3
source share
2 answers

Was this guide working for you? I would get the following data:

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]));
+3
source

, Florent Pillet NSLogger: https://github.com/fpillet/NSLogger

, NSLogger , :

#import "LoggerClient.h"

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

, iphone, , . , , , , ..

+1

Source: https://habr.com/ru/post/1716410/


All Articles