iOS截屏

来源:互联网 发布:中国软件外包公司 编辑:程序博客网 时间:2024/06/03 09:24

-(void)ScreenShots{    CGSize imageSize = [[UIScreen mainScreen] bounds].size;    if (NULL != UIGraphicsBeginImageContextWithOptions) {        UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);    }    else    {        UIGraphicsBeginImageContext(imageSize);    }        CGContextRef context = UIGraphicsGetCurrentContext();        for (UIWindow * window in [[UIApplication sharedApplication] windows]) {        if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) {            CGContextSaveGState(context);            CGContextTranslateCTM(context, [window center].x, [window center].y);            CGContextConcatCTM(context, [window transform]);            CGContextTranslateCTM(context, -[window bounds].size.width*[[window layer] anchorPoint].x, -[window bounds].size.height*[[window layer] anchorPoint].y);            [[window layer] renderInContext:context];                        CGContextRestoreGState(context);        }    }        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();        UIGraphicsEndImageContext();    NSThread *thread=[[NSThread alloc] initWithTarget:self selector:@selector(saveThread:) object:image];    [thread start];    [thread release];        NSLog(@"Suceeded!");}-(void)saveThread:(UIImage*)image{    NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];    UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);    [pool release];}


原创粉丝点击