Rendering UIView slow performance on iPad 3 - iphone

I'm using straightforward code to capture the UIView, and it has been working beautifully on the iPad 2 and the original iPad. But it's staggeringly slow on the iPad 3. I know I'm pushing more pixels, but the rendering performance is simply unacceptable.
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Please help me in a way to improve the speed of the rendering UIView on the iPad 3.
Thanks.

Related

Save UIView with CALayer.mask as UIImage in iOS 6

I have the following code:
if ([[UIScreen mainScreen] respondsToSelector:#selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(mainView.bounds.size, NO, [UIScreen mainScreen].scale);
}
else {
UIGraphicsBeginImageContext(mainView.bounds.size);
}
[mainView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *saveImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
In mainView, there is a masked subview that does not appear in saveImage when using this method. However, I understand there used to be a UIGetScreenImage method pre iOS 4 that did capture such activity. My question is, what is the best way to capture CALayer activities in iOS 6? Is UIGetScreenImage still private?
I think there was a similar question about a week ago: Mask does not work when capturing a uiview to a uiimage
On iOS6 there is a problem capturing a UIView with the mask applied (btw, in iOS 7 it has been fixed): you capture the image but the mask is not applied.
I posted a lengthy solution which involved applying the mask manually to the captured image. It's not very difficult and I also made a demo project of this. You can download it here:
https://bitbucket.org/reydan/so_imagemask
If I did not understand your problem correctly, please tell me so I can remove this answer.
try getting the presentation layer instead, as it will contain the layer's state.
[mainView.layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];
https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instm/CALayer/presentationLayer

UIButton not rendering correctly in iOS6 when calling renderInContext on CALayer

I'm having this issue that seems to only be occuring in iOS 6. I am calling renderInContext on a view's layer. This view is fairly simple. It has a few UIButtons. The UIImage I get back from the following code seems to be corrupted. The UIButtons don't seem to be drawing correctly.
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewSnapShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
This code produces a bitmap that looks like this: http://imgur.com/MyMTX
When I run the app in the iPhone 5.1 simulator this problem doesn't seem to be occurring. I'm starting to wonder if it's just a bug in iOS 6.
Anyone run into a similar issue?

Taking a screenshot in-app then putting it in a UIImageView does so at normal resolution

After zooming the iOS simulator up to 100%, i've noticed that my icons which are made by the app through taking a 'screenshot' of a view using this code are in normal resolution, whereas everything else appears to be in retina resolution:
UIGraphicsBeginImageContext(rect.size);
[object.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Any ideas how to make it be in retina resolution?
UIGraphicsBeginImageContext() is not Retina display-aware.
On iOS 4, you'll need to use UIGraphicsBeginImageContextWithOptions() instead, passing 0 as the last argument to have iOS automatically scale it based on the device's screen resolution:
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[object.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

iPhone Screenshots

I've been using UIGetScreenImage() to get a screenshot of a UIImagePickerController. Basically I use the camera overlay and then when I take the screenshot, I have the image that the camera preview had been showing and my overlay on there too, which is exactly what I need.
Now UIGetScreenImage() has been banned, I've not been able to find a way to do this. It just shows black for the camera.
Edit: all of my other views are showing absolutely fine, just not the actual camera preview. Any ideas??!?!?
Here's the code I am using at the moment.
UIGraphicsBeginImageContext(picker.view.bounds.size);
[picker.view.layer renderInContext:UIGraphicsGetCurrentContext()];
CGContextDrawImage(context, bounds, camView.CGImage);
UIImage* screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);
UIGraphicsEndImageContext();
Any ideas how I can get the overlay + the camera image?
Thanks!
This is slightly different than yours.
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *sShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum (sShot, nil, nil, nil);
Does that work?
If not, you might want to try asking over at iphonedevsdk.com since they specialize in all things iPhone.
Have them take a picture. Then overlay your image on top of it.
Create a UIImage from two other UIImages on the iPhone

Convert UIWebview contents to a UIImage

I am using a UIWebView to display HTML formatted text. I am not loading a webpage, just supplying a string of HTML to the UIWebView.
Now I want to animate this UIWebView on screen, actually several of them (2-10 at a time). UIWebView is a little heavy, and although I haven't attempted it yet, I am planning for the worst. (I don't think this is premature optimization, I 'm almost positive this will be an issue)
To get around the problem, I figured I could convert the contents of the UIWebViews to UIImages and animate them instead.
So, my questions are:
How do you convert UIWebview
contents to a UIImage (or
CGImageRef)?
My UIWebViews have
transparent bacgrounds, will the
transparency be carried over to the
UIImage?
Thanks for any suggestions
UIGraphicsBeginImageContext(webview.bounds.size);
[webview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
You might run into issues if the webview dimensions are large because the webview uses a CATiledLayer that doesn't draw everything for memory reasons.
The image will include transparency
I could be wrong but if you set the cache param of CoreAnimation the OS will handle this optimisation for you.
e.g.
[UIView setAnimationTransition:transition forView:self.view cache:YES];