Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 535099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:40:52+00:00 2026-05-13T09:40:52+00:00

I have array with colors as its objects. I want to create an image

  • 0

I have array with colors as its objects. I want to create an image out of it.
Actually, what is happening is , i’m taking the pixel value of each pixel of an image, modify it and store in a mutable array its object. Now want to draw an image from this. How to do that?? ANy idea???

-(UIImage*)modifyPixels:(UIImage*)originalImage {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
    NSMutableArray *result =[[NSMutableArray alloc]init];
    int width = img.size.width;
    int height = img.size.height;
        originalImage = imageView.image;

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    unsigned char *rawData = malloc (height * width * 4);
    NSUInteger bytesPerPixel = 4;
    NSUInteger bytesPerRow = bytesPerPixel * width;
    NSUInteger bitsPerComponent = 8;
    CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
    CGColorSpaceRelease(colorSpace);

    CGContextDrawImage(context, CGRectMake(0, 0, width, height),img.CGImage);
    CGContextRelease(context);
    int byteIndex = 0;
    for (int xx=0;xx<width;xx++){
        for (int yy=0;yy<height;yy++){
    // Now rawData contains the image data in the RGBA8888 pixel format.
            NSLog(@"(%d,%d)",xx,yy);
    NSLog(@"Alpha 255-Value is: %u", rawData[byteIndex + 3]);
    NSLog(@"Red 255-Value is: %u", rawData[byteIndex]);
    NSLog(@"Green 255-Value is: %u",rawData[byteIndex + 1]);
    NSLog(@"Blue 255-Value is: %u",rawData[byteIndex + 2]);
            CGFloat red   = (rawData[byteIndex]+rawData[byteIndex + 1]+rawData[byteIndex + 2]) / 3;
            CGFloat green = red;
            CGFloat blue  = red;
            CGFloat alpha = 255;
            byteIndex += 4;

            UIColor *acolor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
            [result addObject:acolor];
                }

        }
        UIImage *newImage;  
        //CREATE NEW UIIMAGE (newImage) HERE from acolor(array of colors)
//this is the portion i'm in trouble with

        return newImage;    
        [pool release];
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:40:52+00:00Added an answer on May 13, 2026 at 9:40 am

    As far as I understand you try average all channels.
    You could try the following approach which uses Core Graphics:

    CGImageRef inImage = mainImageView.image.CGImage;          
    CFDataRef dataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));  
    UInt8* pixelBuffer = (UInt8*)CFDataGetBytePtr(dataRef);  
    int length = CFDataGetLength(dataRef);  
    for (int index = 0; index < length; index += 4)  
    {  
        pixelBuffer[index + 1] = (pixelBuffer[index + 1] + pixelBuffer[index + 2] + pixelBuffer[index + 3])/3.0;  
        pixelBuffer[index + 2] = pixelBuffer[index + 1];  
        pixelBuffer[index + 3] = pixelBuffer[index + 1];      
    }  
    CGContextRef ctx = CGBitmapContextCreate(pixelBuffer,  
                                             CGImageGetWidth( inImage ),  
                                             CGImageGetHeight( inImage ),  
                                             8,  
                                             CGImageGetBytesPerRow( inImage ),  
                                             CGImageGetColorSpace( inImage ),  
                                             kCGImageAlphaPremultipliedFirst );  
    CGImageRef imageRef = CGBitmapContextCreateImage(ctx);  
    UIImage* rawImage = [UIImage imageWithCGImage:imageRef];  
    CGContextRelease(ctx);  
    CFRelease(dataRef);
    CGImageRelease(imageRef);
    

    The result is stored in rawImage.

    You could also take a look at the GLImageProcessing sample from Apple.
    This shows some basic image processing techniques on the iPhone using OpenGL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 370k
  • Answers 370k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is so easy to reproduce the issue Create a… May 14, 2026 at 6:34 pm
  • Editorial Team
    Editorial Team added an answer Templates are just here to simplify the life. If you… May 14, 2026 at 6:34 pm
  • Editorial Team
    Editorial Team added an answer I have looked for actual data for the past days,… May 14, 2026 at 6:34 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.