Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

CGImageRef UIGetScreenImage();

 

- (UIImage *) getScreenImage:(UIView *)shotView{

 

    CGImageRef cgImage = UIGetScreenImage();

 

    void *imageBytes = NULL;

 

    if (cgImage == NULL) {

 

        CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();

 

        imageBytes = malloc(shotView.bounds.size.width * shotView.bounds.size.height * 4);

 

        CGContextRef context = CGBitmapContextCreate(imageBytes, shotView.bounds.size.width, shotView.bounds.size.height, 8, shotView.bounds.size.width * 4, colorspace, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big);

 

        CGColorSpaceRelease(colorspace);

 

        for (UIWindow *window in [[UIApplication sharedApplication] windows]) {

 

            CGRect bounds = [window bounds];

 

            CALayer *layer = [window layer];

 

            CGContextSaveGState(context);

 

            if ([layer contentsAreFlipped]) {

 

                CGContextTranslateCTM(context, 0.0f, bounds.size.height);

 

                CGContextScaleCTM(context, 1.0f, -1.0f);

 

            }

 

            [layer renderInContext:(CGContextRef)context];

 

            CGContextRestoreGState(context);

 

        }

 

        cgImage = CGBitmapContextCreateImage(context);

 

        CGContextRelease(context);

 

    }

 

    UIImage *resultingImage = [UIImage imageWithCGImage:cgImage];

 

    CGImageRelease(cgImage);

 

    return resultingImage;

 

}

  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.