zoukankan      html  css  js  c++  java
  • iOS-截图和把截图封装成一个方法

    //
    //  UIImage+Tools.h
    //  截屏
    //
    //  Created by YaguangZhu on 15/9/10.
    //  Copyright (c) 2015年 YaguangZhu. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface UIImage (Tools)
    +(instancetype)imageWithCaptureView:(UIView *)view;
    
    @end
    
    
    
    //
    //  UIImage+Tools.m
    //  截屏
    //
    //  Created by YaguangZhu on 15/9/10.
    //  Copyright (c) 2015年 YaguangZhu. All rights reserved.
    //
    
    #import "UIImage+Tools.h"
    
    @implementation UIImage (Tools)
    
    + (instancetype)imageWithCaptureView:(UIView *)view
    {
        UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        [view.layer renderInContext:ctx];
        
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        
        UIGraphicsEndImageContext();
        
        return newImage;
    }
    @end
    //
    //  ViewController.m
    //  截屏
    //
    //  Created by YaguangZhu on 15/9/10.
    //  Copyright (c) 2015年 YaguangZhu. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "UIImage+Tools.h"
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        UIImage *newImage = [UIImage imageWithCaptureView:self.view];
        NSData *data = UIImagePNGRepresentation(newImage);
        
        [data writeToFile:@"/Users/yaguangzhu/Desktop/00d1.png" atomically:YES];
    
        
    }
    - (void)CaptureView
    {
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.0);
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        [self.view.layer renderInContext:ctx];
        
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        
        UIGraphicsEndImageContext();
        NSData *data = UIImagePNGRepresentation(newImage);
        
        [data writeToFile:@"/Users/yaguangzhu/Desktop/00d1.png" atomically:YES];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    递归判断回文
    从小工到专家阅读笔记1
    建立SQL全文索引提升搜索速度
    数据库SQLServer经验小记
    [转]C#中调用SQL存储过程(带输入输出参数的例子)
    20101124 14:55 全文索引是解决海量数据模糊查询的较好解决办法
    使用SQL Server 2008提供的表分区向导
    千万级SQL Server数据库表分区的实现
    C#调用存储过程简单完整例子
    SQL server 海量数据库的查询优化及分页算法(收藏)
  • 原文地址:https://www.cnblogs.com/zhuyaguang/p/4797262.html
Copyright © 2011-2022 走看看