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];
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With