zoukankan      html  css  js  c++  java
  • IOS 截屏

    UIImage+Screenshot.h
    
    #import <UIKit/UIKit.h>
    
    @interface UIImage (Screenshot)
    
    + (UIImage *)screenshot;
    
    @end
    
    
    #import "UIImage+Screenshot.h"
    
    @implementation UIImage (Screenshot)
    
    + (UIImage *)screenshot
    {
        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();
        
        return image;
    }
    
    @end

    // 使用

      UIImage *image = [UIImage screenshot];

     
  • 相关阅读:
    Linux服务安全之TcpWrapper篇
    通过cmd命令到ftp上下载文件
    常见tcp端口
    cmd常用命令
    TeeChart的最小步长和最大步长
    根据指定的commit查找对应的log
    WCF
    在IIS中某一个网站启用net.tcp
    wcf 远程终结点已终止该序列 可靠会话出错
    IIS中的Application.CommonAppDataPath
  • 原文地址:https://www.cnblogs.com/joesen/p/4074069.html
Copyright © 2011-2022 走看看