开发者

iphone sdk: Creating an image of the contents of the screen?

开发者 https://www.devze.com 2022-12-09 15:16 出处:网络
I\'开发者_Python百科m looking for a way to write the contents of the screen to an image. Any idea how to achieve that? Does it involve using Quartz?

I'开发者_Python百科m looking for a way to write the contents of the screen to an image. Any idea how to achieve that? Does it involve using Quartz?

Thanks


Add this code to your UIViewController to create a screen dump of its UIView.

// create screen dump of the view of this view controller
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// save image to photos
UIImageWriteToSavedPhotosAlbum(screenShot, self, nil, nil);


In a nutshell:

CGImageRef screen = UIGetScreenImage();
UIImage *screenImage = [UIImage imageWithCGImage:screen];
0

精彩评论

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

关注公众号