title: Image resized error: CGBitmapContextCreate: unsupported parameter
body: <p>I am using the following code (from a blog post) to resize an image </p>
  
  <pre><code>if (inImage.size.width &lt;= inImage.size.height) {
      // Portrait
      ratio = inImage.size.height / inImage.size.width;
      resizedRect = CGRectMake(0, 0, width, width * ratio);
  }
  else {
      // Landscape
      ratio = inImage.size.width / inImage.size.height;
      resizedRect = CGRectMake(0, 0, height * ratio, height);
  }
  
  CGImageRef          imageRef = [inImage CGImage];
  CGImageAlphaInfo    alphaInfo = CGImageGetAlphaInfo(imageRef);
  
  if (alphaInfo == kCGImageAlphaNone)
      alphaInfo = kCGImageAlphaNoneSkipLast;
  
  CGContextRef bitmap = CGBitmapContextCreate(
                                              NULL,
                                              resizedRect.size.width,     // width
                                              resizedRect.size.height,        // height
                                              CGImageGetBitsPerComponent(imageRef),   // really needs to always be 8
                                              4 * resizedRect.size.width, // rowbytes
                                              CGImageGetColorSpace(imageRef),
                                              alphaInfo
                                              );
  </code></pre>
  
  <p>but for some reason depending on the size I am try to resize to I get the following error generated</p>
  
  <blockquote>
    <p>CGBitmapContextCreate: unsupported
    parameter combination: 8 integer
    bits/component; 32 bits/pixel;
    3-component colorspace;
    kCGImageAlphaNoneSkipFirst; XXX
    bytes/row.</p>
  </blockquote>
  
  <p>where XXX differs depending on which image.</p>
  
  <p>The rect I am creating is propotional to the image, I take a ratio from the width/height (depending on aspect) and multiple that be target width/height.</p>
  
  <p>Here are some examples (X errors, / doesnt), the resize size will be 50xX or Xx50 depending on aspect:</p>
  
  <pre><code>Source   50x50   69x69
  430x320  /      X
  240x320  /      /
  272x320  /      /
  480x419  /      X
  426x320  X      X
  480x256  X      X
  </code></pre>