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];
    }