-drawViewHierarchyInRect:afterScreenUpdates:
is a fast way in iOS 7 to take a snapshot of a view hierarchy.
It takes snapshots but with @1x resolution. The snapshots look pixellated and blurry on an iPhone 5S. The view from which I create a snapshot is not transformed.
I don't want to blur it and want good quality as seen on screen. Here is how I capture it:
UIGraphicsBeginImageContext(self.bounds.size);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I also tried:
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, self.contentScaleFactor);
which still renders with low @1x quality.
Is there another way to configure the image context so it's @2x resolution?
The correct one would be:
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0f);
OK, so the problem was that self.contentScaleFactor returns a wrong value on a retina display device. It is 1 where it should be 2.
This works, but of course it's less than ideal because it has no fallback for non-retina devices.
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 2);
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