title: How to create circular CGRect
body: <p>I am using this code to create the rectangle in my app. But i want to make it rounded. How can i do that.</p>
  
  <pre><code>- (void)setCropRect:(CGRect)cropRect
  {
      if(!CGRectEqualToRect(_cropRect,cropRect)){
          _cropRect = CGRectOffset(cropRect, self.frame.origin.x, self.frame.origin.y);
          UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.f);
          CGContextRef context = UIGraphicsGetCurrentContext();
          [[UIColor blackColor] setFill];
          UIRectFill(self.bounds);
          CGContextSetStrokeColorWithColor(context, [[UIColor whiteColor] colorWithAlphaComponent:0.5].CGColor);
          CGContextStrokeRect(context, cropRect);
          [[UIColor clearColor] setFill];
          UIRectFill(CGRectInset(cropRect, 1, 1));
          self.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
  
          UIGraphicsEndImageContext();
      }
  }
  </code></pre>
  
  <p>I am using this code to crop the image in rectangular shape:</p>
  
  <pre><code>- (CGImageRef)newTransformedImage:(CGAffineTransform)transform
                       sourceImage:(CGImageRef)sourceImage
                      sourceSize:(CGSize)sourceSize
             sourceOrientation:(UIImageOrientation)sourceOrientation
                   outputWidth:(CGFloat)outputWidth
                      cropRect:(CGRect)cropRect
                 imageViewSize:(CGSize)imageViewSize
  {
      CGImageRef source = sourceImage;
  
      CGAffineTransform orientationTransform;
      [self transform:&amp;orientationTransform andSize:&amp;imageViewSize forOrientation:sourceOrientation];
  
      CGFloat aspect = cropRect.size.height/cropRect.size.width;
      CGSize outputSize = CGSizeMake(outputWidth, outputWidth*aspect);
  
      CGContextRef context = CGBitmapContextCreate(NULL,
                                                   outputSize.width,
                                                   outputSize.height,
                                                   CGImageGetBitsPerComponent(source),
                                                   0,
                                                   CGImageGetColorSpace(source),
                                                   CGImageGetBitmapInfo(source));
      CGContextSetFillColorWithColor(context,  [[UIColor clearColor] CGColor]);
      CGContextFillRect(context, CGRectMake(0, 0, outputSize.width, outputSize.height));
  
      CGAffineTransform uiCoords = CGAffineTransformMakeScale(outputSize.width/cropRect.size.width,
                                                              outputSize.height/cropRect.size.height);
      uiCoords = CGAffineTransformTranslate(uiCoords, cropRect.size.width/2.0, cropRect.size.height/2.0);
      uiCoords = CGAffineTransformScale(uiCoords, 1.0, -1.0);
      CGContextConcatCTM(context, uiCoords);
  
      CGContextConcatCTM(context, transform);
      CGContextScaleCTM(context, 1.0, -1.0);
      CGContextConcatCTM(context, orientationTransform);
  
      CGContextDrawImage(context, CGRectMake(-imageViewSize.width/2.0,
                                             -imageViewSize.height/2.0,
                                             imageViewSize.width,
                                             imageViewSize.height)
                         ,source);
  
  
  
      CGImageRef resultRef = CGBitmapContextCreateImage(context);
      CGContextRelease(context);
      return resultRef;
  }
  </code></pre>
  
  <p>Is i can use the brazier curve to crop the image also.</p>