title: CGImageCreate Test Pattern is not working (iOS)
body: <p>I'm trying to create an UIImage test pattern for an iOS 5.1 device.  The target UIImageView is 320x240 in size, but I was trying to create a 160x120 UIImage test pattern (future, non-test pattern images will be this size).  I wanted the top half of the box to be blue and the bottom half to be red, but I get what looks like uninitialized memory corrupting the bottom of the image.  The code is as follows:</p>
  
  <pre><code>int width = 160;
  int height = 120;
  unsigned int testData[width * height];
  for(int k = 0; k &lt; (width * height) / 2; k++)
      testData[k] = 0xFF0000FF;   // BGRA (Blue)
  for(int k = (width * height) / 2; k &lt; width * height; k++)
      testData[k] = 0x0000FFFF;   // BGRA (Red)
  
  int bitsPerComponent = 8;
  int bitsPerPixel = 32;
  int bytesPerRow = 4 * width;
  CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, &amp;testData, (width * height * 4), NULL);
  CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();      
  CGBitmapInfo bitmapInfo = kCGImageAlphaNoneSkipFirst;
  CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
  
  CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, 
                                      colorSpaceRef, bitmapInfo, provider, NULL, NO,renderingIntent);
  
  UIImage *myTestImage = [UIImage imageWithCGImage:imageRef];
  </code></pre>
  
  <p>This should look like another example on Stack Overflow.  Anyway, I found that as I decrease the size of the test pattern the "corrupt" portion of the image increases.  What is also strange is that I see lines of red in the "corrupt" portion, so it doesn't appear that I'm just messing up the sizes of components.  What am I missing?  It feels like something in the provider, but I don't see it.</p>
  
  <p>Thanks!   </p>
  
  <p>Added screenshots.  Here is what it looks like with kCGImageAlphaNoneSkipFirst set:</p>
  
  <p><img src="https://i.stack.imgur.com/h4toi.png" alt="AlphaSkipFirst"></p>
  
  <p>And here is what it looks like with kCGImageAlphaFirst:</p>
  
  <p><img src="https://i.stack.imgur.com/KxS25.png" alt="enter image description here"></p>