zoukankan      html  css  js  c++  java
  • 屏幕截屏——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;
    
    }
  • 相关阅读:
    python2.7学习记录之三
    编程题
    解题的小问题(C++)
    算法入门(C++)
    逻辑回归
    入门级(python)
    python2.7学习记录之二
    sql语句-排序后加入序号再运算判断取想要的项
    linux中c多线程同步方法
    进程间的通讯方式
  • 原文地址:https://www.cnblogs.com/gaoxiao228/p/3079210.html
Copyright © 2011-2022 走看看