Resolution Loss when generating an Image from UIImageView

98 views Asked by At

Okay, sorry if the title is a little confusing. Basically I am trying get the image/subviews of the image view and combine them into a single exportable UIImage.

Here is my current code, however it has a large resolution loss.

func generateImage() -> UIImage{
    UIGraphicsBeginImageContext(environmentImageView.frame.size)
    var context : CGContextRef = UIGraphicsGetCurrentContext()
    environmentImageView.layer.renderInContext(context)
    var img : UIImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return img
}
1

There are 1 answers

0
Jack On BEST ANSWER

You have to set the scale of the context to be retina.

UIGraphicsBeginImageContextWithOptions(environmentImageView.frame.size, false, 0)

0 means to use the scale of the screen which will work for non-retina devices as well.