1

I have AVFoundation framework in my project and I am taking a screenshot with the previewLayer visible. When I take the screen shot the image appears to be stretched a little bit. How can I fix the stretching issue?

CGSize imageSize = [[UIScreen mainScreen] bounds].size;


         UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);

         CGContextRef context = UIGraphicsGetCurrentContext();

       UIGraphicsPushContext(context);
         [image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
         UIGraphicsPopContext();




         [self renderView:self.overlayLabel inContext:context];



         UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
         self.screenshotImage = screenshot;
         UIGraphicsEndImageContext();

         UIImageWriteToSavedPhotosAlbum(screenshot, self, nil, nil);
Ro4ch
  • 850
  • 8
  • 21
  • 1
    First of all you don't need to push or pop the context - that's done automatically for you. Second of all, you're drawing your image at the size of the screen - so if the image doesn't have the same aspect ratio as the screen, it will be stretched. You'll either want to use a `UIImageView` with a `.ScaleAspectFit` content mode, and draw that in the context, or calculate the rect of the image that will aspect-ly fit in your context. [My answer here](http://stackoverflow.com/questions/35507331/aspect-fit-programmatically-in-ios/35510271#35510271) might be useful for that. – Hamish Apr 03 '16 at 21:32

0 Answers0