• 屏幕截屏——UIGetScreenImage .


    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;
    
    }
  • 相关阅读:
    Lambda表达式
    多态的实现原理
    泛型
    tomcat
    nginx
    列举cocoa touch 常用框架
    写出你对MVC模式的理解
    写一个委托的interface
    写一个“标准”宏MIN 这个宏输入两个参数并返回较小的一个
    简介Object-C的内存管理
  • 原文地址:https://www.cnblogs.com/gaoxiao228/p/3079210.html
Copyright © 2020-2023  润新知