RenderInContext for retina and non-retina devices

I create a PDF by taking a screenshot of UIView, it currently works great on iPad3 with a retina display, but when testing on other devices with lower resolution screens, I have problems with text resolution.

Here is my code:

//start a new page with default size and info //this can be changed later to include extra info. UIGraphicsBeginPDFPage(); //render the view layer into an image context //the last option specifies scale. If 0, it uses the devices scale. UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 2.0); CGContextRef context = UIGraphicsGetCurrentContext(); [view.layer renderInContext:context]; UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); //render the screenshot into the pdf page CGContext [screenShot drawInRect:view.bounds]; //close the pdf context (saves the pdf to the NSData object) UIGraphicsEndPDFContext(); 

I also tried setting the scale of UIGraphicsBeginImageContextWithOptions to 2.0, but this does not give any changes. How to make iPad2 image display with 2x resolution?

Expected Result:

Imgur

Actual output:

Imgur

+7
source share
1 answer

I ended up fixing this by recursively setting the contentScaleFactor property of the parent view, and its routines to 2.0.

UIImage showed the correct resolution, but the layer was not when renderInContext was called.

+5
source

All Articles