开发者

Not able to take the screenshots in a viewcontroller view of xcode

I'm reading pdf's in a view and trying to capture screenshots of pdf pages. UIGraphicsGetImageFromCurrentImageContext() doesn't wor开发者_C百科k. any solutions?


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....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜