tags:

views:

8

answers:

1

I'm reading pdf's in a view and trying to capture screenshots of pdf pages. UIGraphicsGetImageFromCurrentImageContext() doesn't work. any solutions?

A: 

That only works when the current image context is relevant, for instance if you are calling this within the drawRect method of a UIView then you have the context relating to the view.

Instead you need to create a new graphics context and render the view into it...

UIGraphicsBeginImageContext(view.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect area = CGRectMake(0, 0, view.size.width, view.size.height);

CGContextDrawImage(ctx, area, view.layer.CGImage);

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
UIGraphicsEndImageContext();

This is from memory so I hope this is correct but you get the idea....

Simon Lee
Got it. Thanku :)
preeti