不用 2d截图 直接截图
-(UIImage *)screenShots
{
//截取整个backview
UIGraphicsBeginImageContext(self.backgroundView.bounds.size);
[self.backgroundView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *sourceImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//在截图上画下自己需要的位置及大小
UIGraphicsBeginImageContext(self.mainContentView.frame.size);
[sourceImage drawAtPoint:CGPointMake(0, self.mainContentView.bounds.size.height - self.view.bounds.size.height)];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsGetCurrentContext();
return image;
}
上面的方法会压缩图片,用下面的方法可以设置是否缩放图片
UIGraphicsBeginImageContextWithOptions( self.view.frame.size, NO, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *sourceImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
网友评论