Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Coregraphics image poor quality

I am not sure whether I can improve image quality but following code displays very poor image quality in PDF. I know its standard code to generate images from view but is there anything I could do to specify image quality or improve it?

- (void)renderView:(UIView*)view {
    UIGraphicsBeginImageContext(view.frame.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewAsImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    [viewAsImage drawInRect:rect];
}
like image 828
AlienMonkeyCoder Avatar asked Feb 15 '23 19:02

AlienMonkeyCoder


1 Answers

You probably need to create a graphics context with a scale of 2 (retina) instead of the default 1. To do so, use UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, 0.0);. This will create an image context with an opaque target (you can set the second parameter to NO if you're rendering a transparent image) and with a scale factor of your device's main screen.

like image 157
StatusReport Avatar answered Feb 27 '23 12:02

StatusReport