开发者

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

开发者 https://www.devze.com 2023-01-11 05:20 出处:网络
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 imag

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

精彩评论

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