title: Best way to get data image for processing
body: <p>i want to get data from uiimage to read rgb values. I want to use this data for convolution filters. In the internet i found only one method:</p>
  
  <pre><code>// First get the image into your data buffer
  CGImageRef image = [UIImage CGImage];
  NSUInteger width = CGImageGetWidth(image);
  NSUInteger height = CGImageGetHeight(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));
  CGContextRelease(context);
  
  // Now your rawData contains the image data in the RGBA8888 pixel format.
  int byteIndex = (bytesPerRow * yy) + xx * bytesPerPixel;
  red = rawData[byteIndex];
  green = rawData[byteIndex + 1];
  blue = rawData[byteIndex + 2];
  alpha = rawData[byteIndex + 3];
  </code></pre>
  
  <p>Its ok but i want to working with pixels on array some like this: [x][y][r,b,g].</p>
  
  <p>How Can i solve it? </p>