zoukankan      html  css  js  c++  java
  • iOS截屏功能

    代码:

    复制代码
    复制代码
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        //初始化界面
        [self addView];
        
    }
    #pragma -mark -functions
    //初始化界面
    -(void)addView
    {
        UIImage *image = [self screenshot:UIDeviceOrientationPortrait
                                 isOpaque:YES
                     usePresentationLayer:YES];
        
        UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)];
        imageView.backgroundColor=[UIColor redColor];
        imageView.image=image;
        [self.view addSubview:imageView];
    
    }
    //截屏功能
    - (UIImage *)screenshot:(UIDeviceOrientation)orientation isOpaque:(BOOL)isOpaque usePresentationLayer:(BOOL)usePresentationLayer
    {
        CGSize size;
        
        if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
            size = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
        } else {
            size = CGSizeMake(self.view.frame.size.height, self.view.frame.size.width);
        }
        
        UIGraphicsBeginImageContextWithOptions(size, isOpaque, 0.0);
        
        if (usePresentationLayer) {
            [self.view.layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];
        } else {
            [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        }
        
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        
        UIGraphicsEndImageContext();
        
        return image;
    }
  • 相关阅读:
    java基础-数组
    泛型 --集合
    单例模式(新)
    static 关键字
    单例模式
    迭代器模式(java版)
    Object类
    JavaWeb学习总结(十七)——JSP中的九个内置对象
    javaweb学习总结(十六)——JSP指令
    javaweb学习总结(十五)——JSP基础语法
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/6950453.html
Copyright © 2011-2022 走看看