• 屏幕截图


    Main.storyboard

    ViewController.m

    //

    //  ViewController.m

    //  6A03.屏幕截图

    //

    //  Created by huan on 16/1/30.

    //  Copyright © 2016 huanxi. All rights reserved.

    //

     

    #import "ViewController.h"

     

    @interface ViewController ()

     

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

    }

     

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

        // 截取当前view 成为一张图片

        

        //使用位图上下文

        //1. 开启位图上下文

        UIGraphicsBeginImageContext(self.view.bounds.size);

        //2. 当前控制器的view画在位图上下文 render 渲染

        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

        //3.获得图片

        UIImage *captureImg = UIGraphicsGetImageFromCurrentImageContext();

        //4.结束位图编辑

        UIGraphicsEndImageContext();

        //save Image

        NSData *imgData = UIImagePNGRepresentation(captureImg);

    #warning 平时开发过程中,图片保存是沙盒

        [imgData writeToFile:@"/Users/huan/Desktop/capture.png" atomically:YES];

        

    }

     

    @end

           

  • 相关阅读:
    百度之星初赛 A
    百度之星 初赛 BC
    2016 百度之星资格赛
    codeforces 749
    codeforces 785
    HDU 4617
    网络流 poj 2195
    网络流 poj 3436 poj 3281
    codeforces 780 C
    idea激活
  • 原文地址:https://www.cnblogs.com/Lu2015-10-03/p/5177801.html
Copyright © 2020-2023  润新知