您的位置:首页 > 移动开发 > IOS开发

【工作随笔】iOS 屏幕截屏

2015-05-27 14:43 381 查看
iOS 屏幕截屏

1. 截取当前屏幕

UIGraphicsBeginImageContextWithOptions(CGSizeMake(screenWidth*screenScale, screenHeight*screenScale), YES, 0);
//设置截屏大小
[[[[UIApplication sharedApplication] keyWindow] layer] renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

CGImageRef imageRef = viewImage.CGImage;
CGRect rect = CGRectMake(0, 0, screenWidth*screenScale,screenHeight*screenScale);

CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect);
UIImage *sendImage = [[UIImage alloc] initWithCGImage:imageRefRect];


2. 从view上截图

UIGraphicsBeginImageContextWithOptions(CGSizeMake(150, 150), NO, 1.0);  //NO,YES 控制是否透明
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// 生成后的image


3.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: