title: <Error>: CGBitmapContextCreate: unsupported parameter combination vs. lower resolution image
body: <pre><code>- (UIImage *)roundedCornerImage:(NSInteger)cornerSize borderSize:(NSInteger)borderSize {
      // If the image does not have an alpha layer, add one
      UIImage *image = [self imageWithAlpha];
  
      // Build a context that's the same dimensions as the new size
      CGBitmapInfo info = CGImageGetBitmapInfo(image.CGImage);
      CGContextRef context = CGBitmapContextCreate(NULL,
                                               image.size.width,
                                               image.size.height,
                                               CGImageGetBitsPerComponent(image.CGImage),
                                               0,
                                               CGImageGetColorSpace(image.CGImage),
                                               CGImageGetBitmapInfo(image.CGImage));
  
      // Create a clipping path with rounded corners
      CGContextBeginPath(context);
      [self addRoundedRectToPath:CGRectMake(borderSize, borderSize, image.size.width - borderSize * 2, image.size.height - borderSize * 2)
                     context:context
                   ovalWidth:cornerSize
                  ovalHeight:cornerSize];
      CGContextClosePath(context);
      CGContextClip(context);
  
      // Draw the image to the context; the clipping path will make anything outside the rounded rect transparent
      CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
  
      // Create a CGImage from the context
      CGImageRef clippedImage = CGBitmapContextCreateImage(context);
      CGContextRelease(context);
  
      // Create a UIImage from the CGImage
      UIImage *roundedImage = [UIImage imageWithCGImage:clippedImage];
      CGImageRelease(clippedImage);
  
      return roundedImage;
  }
  </code></pre>
  
  <p>I have the method above and am adding rounded corners to Twitter profile images. For most of the images this works awesome. There are a few that cause the following error to occur:</p>
  
  <blockquote>
    <p>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 96 bytes/row.</p>
  </blockquote>
  
  <p>I have done some debugging and it looks like the only difference from the images causing errors and the ones that are not is the parameter, CGImageGetBitmapInfo(image.CGImage), when creating the context. This throws the error and results in the context being null. I tried setting the last parameter to kCGImageAlphaPremultipliedLast to no avail either. The image is drawn this time but with much less quality. Is there a way to get a higher quality image on par with the rest of them? The path to the image is via Twitter so not sure if they have different ones you can pull.</p>
  
  <p>I have seen the other questions regarding this error too. None of have solved this issue. I saw <a href="https://stackoverflow.com/questions/2457116/iphone-changing-cgimagealphainfo-of-cgimage">this post</a> but the errored images are completely blurry after that. And casting the width and height to NSInteger also didn't work.  Below is a screenshot of the two profile images and their quality as well. The first one is causing the error.</p>
  
  <p><img src="https://i.stack.imgur.com/vrkKW.png" alt="Here is a screenshot of the two images and their quality"> </p>
  
  <p>Does anyone have any idea what the issue is here?</p>
  
  <p>Thanks a ton. This has been killing me.</p>