美文网首页
iOS截取整个屏幕

iOS截取整个屏幕

作者: Leo_hai | 来源:发表于2016-04-15 11:11 被阅读645次
    +(UIImage*) imageByCaptureScreen  {
       if(UIGraphicsBeginImageContextWithOptions!=NULL)
    {
    UIGraphicsBeginImageContextWithOptions([UIScreenmainScreen].bounds.size,NO,0);
    }
    else
    {
    UIGraphicsBeginImageContext([UIScreenmainScreen].bounds.size);
    }
    CGContextRefcontext =UIGraphicsGetCurrentContext();
    for(UIWindow*windowin[[UIApplicationsharedApplication]windows])
    {
    if(![windowrespondsToSelector:@selector(screen)] || [windowscreen] == [UIScreenmainScreen])
    {
    CGContextSaveGState(context);
    CGContextTranslateCTM(context, [windowcenter].x, [windowcenter].y);
    CGContextConcatCTM(context, [windowtransform]);
    if(IOS7_OR_LATER)
    {
    CGContextTranslateCTM(context,
    -[windowbounds].size.width* [[windowlayer]anchorPoint].x,
    -[windowbounds].size.height* [[windowlayer]anchorPoint].y);
    }
    else
    {
    CGContextTranslateCTM(context,
    -[windowbounds].size.width* [[windowlayer]anchorPoint].x,
    -[windowbounds].size.height* [[windowlayer]anchorPoint].y-20);
    }
    [[windowlayer]renderInContext:context];
    
    CGContextRestoreGState(context);
    
    }
    
    }
    
    UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    returnimage;
    
     }

    相关文章

      网友评论

          本文标题:iOS截取整个屏幕

          本文链接:https://www.haomeiwen.com/subject/kvknlttx.html