title: UIImage with CGAffineTransform drawn in CGContext strange output
body: <p>I have a UIView containing a UIImageView, I apply a rotation transform to the UIImageView and then want to draw that image with same rotation transform in a CGContext (and in future more transforms like translation and scale will be used), I have following code to make the transformation and drawing in CGContext:</p>
  
  <pre><code>UIImage *image=[UIImage imageNamed:@"cena-1.png"];
  CGRect imageFrame=CGRectMake(50, 50, image.size.width, image.size.height);
  UIImageView *imageView=[[UIImageView alloc] initWithFrame:imageFrame];
  imageView.image=image;
  [self.view addSubview:imageView];
  
  CGAffineTransform imageTransform=CGAffineTransformMakeRotation(degreesToRadians(10));
  imageView.transform=imageTransform;
  NSLog(@"self.imgOverlay.image.scale: %f", imageView.image.scale);
  
  UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
  CGContextRef context = UIGraphicsGetCurrentContext();
  UIGraphicsPushContext(context);
  
  CGContextConcatCTM(context, imageView.transform);
  
  CGRect modifiedRect=CGRectApplyAffineTransform(imageFrame, imageTransform);
  [imageView.image drawInRect:modifiedRect];
  
  UIGraphicsPopContext();
  UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  
  NSString *jpgPath=[NSTemporaryDirectory() stringByAppendingPathComponent:@"test.jpg"];
  NSData *imageData=UIImageJPEGRepresentation(outputImage, 1.0);
  [imageData writeToFile:jpgPath atomically:YES];
  
  NSLog(@"putputImage path: %@", jpgPath);
  </code></pre>
  
  <p>.</p>
  
  <p>The problem is the outputimage doesn't look same as it is shown in UIKit's UIVIew, it gets skewed and position is not accurate as well, here is a screenshot:</p>
  
  <p><img src="https://i.stack.imgur.com/ttM0m.png" alt="enter image description here"></p>
  
  <p>Please guide me on what I am doing wrong, thanks for your help :)</p>
  
  <p>p.s. I have also posted another question (<a href="https://stackoverflow.com/questions/17873202/uiimage-drawn-in-cgcontext-with-cgaffinetransform-unexpected-results">https://stackoverflow.com/questions/17873202/uiimage-drawn-in-cgcontext-with-cgaffinetransform-unexpected-results</a>) with explaining the complete scenario however answer to this question will hopefully be enough.</p>
  
  <p><strong>UPDATE</strong>
  I have tried <code>[imageView.image drawAtPoint:modifiedRect.origin];</code> it corrects the skew problem (<a href="http://screencast.com/t/v2oKkmkd" rel="nofollow noreferrer">http://screencast.com/t/v2oKkmkd</a>) but the position issue remains :(</p>
  
  <p><strong>UPDATE 2</strong>
  Here is a test project with a little modified code: <a href="https://github.com/abduliam/TestTransform" rel="nofollow noreferrer">https://github.com/abduliam/TestTransform</a></p>