开发者

Need to create a snapshot of a view at runtime

i need to take a snapshot of my current ipad-view. That view loads and plays a video. I found this function which works almost really well.

- (UIImage*)captureView:(UIView *)view {
    CGRect rect =  [[UIScreen mainScreen] bounds];   
    UIGraphicsBeginImageContext(rect.size);  
    CGContextRef context = UIGraphicsGetCurrentContext();    
    [view.layer renderInContext:context];    
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();     
    return img;
}

(Source from: LINK)

The problem is, that the current frame of the playing video is not captured, only the view but without video-content. Do i forgot to update the display or anything else before saving the image? Is there a special function that reads the latest screen-v开发者_开发知识库alues?

Thanks for your time and help.


Have you tried using the UIGetScreenImage() function?

It's private, but Apple allows to use it, so your app will be validated for the App Store, even if you use it.

You just need to declare its prototype, so the compiler won't complain:

CGImageRef UIGetScreenImage( void );

Note: you can create a NSImage from the CGImageRef with the following NSImage method:

- ( id )initWithCGImage: ( CGImageRef )cgImage size:( NSSize )size;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜