title: How to add colors into pixel by pixel on image on iphone?
body: <p>This is my first assignment about image processing. I'm assuming index of each pixel on output image are represented as matrix below:</p>
  
  <pre><code>00 01 02 03 04 05
  
  10 11 12 13 14 15
  
  20 21 22 23 24 25
  </code></pre>
  
  <p>At each index of output image I have different color to draw on. For ex, at index 00 I have redcolor available to put there and so on with other indexes. My question is how can I draw these color into the indexes to create the output image?  </p>
  
  <p><strong>Update</strong></p>
  
  <p>This is what I have right now:</p>
  
  <pre><code> inputImgAvg //Image for processing
   CGContextRef context = UIGraphicsGetCurrentContext();
  
   float  yy = groutW / 2;            // skip over grout on edge
       float stride =(int) (tileW + groutW +0.5);
          for(int y=0; y&lt;tilesY; y++) {               //Number tile in Y direction
              float xx = groutW / 2 ;         // skip over grout on edge
              for(int x=0; x&lt;tilesX; x++) {
                  tileRGB = [inputImgAvg colorAtPixel:CGPointMake(x,y)];
  
                  //Right here I'm checking tileRGB with list of available color
                  //Find out the closest color 
                  //Now i'm just checking with greenColor
  
                  // best matching tile is found in idx position in vector;
                  // scale and copy it into proper location in the output
                  CGContextSetFillColor(context, CGColorGetComponents( [[UIColor greenColor] CGColor]));
  </code></pre>
  
  <p>But I got this error. Can you point out what did I do wrong?</p>
  
  <pre><code>&lt;Error&gt;: CGContextSetFillColor: invalid context 0x0
  &lt;Error&gt;: CGContextFillRects: invalid context 0x0
  </code></pre>