博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS-截图和把截图封装成一个方法
阅读量:4919 次
发布时间:2019-06-11

本文共 1937 字,大约阅读时间需要 6 分钟。

////  UIImage+Tools.h//  截屏////  Created by YaguangZhu on 15/9/10.//  Copyright (c) 2015年 YaguangZhu. All rights reserved.//#import 
@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

 

转载于:https://www.cnblogs.com/zhuyaguang/p/4797262.html

你可能感兴趣的文章
VUE一 基础语法
查看>>
[MySQl]MySQL忘记密码
查看>>
Android的minSdkVersion,targetSdkVersion,maxSdkVersion
查看>>
Xceed WinForm数据表格控件Xceed Grid For .NET控件详细介绍及下载地址
查看>>
ecos启动流程分析
查看>>
Oracle CASE WHEN 用法介绍
查看>>
linux 下连接mysql服务器
查看>>
DOMContentLoad 首屏渲染
查看>>
rpm检验是否被改动过
查看>>
Sphinx-简介及原理
查看>>
【Linux】深入理解Linux中内存管理
查看>>
WEB 移动网站 手机点击 打电话 发短信
查看>>
2019CSUST集训队选拔赛题解(一)
查看>>
李晓菁201771010114《面向对象程序设计(Java)》第三周学习总结
查看>>
Typedef与Struct
查看>>
Linux常用网络命令整理
查看>>
C++ 面向对象
查看>>
Maven Nexus
查看>>
js 判断滚动条的滚动方向
查看>>
关于springboot启动时候报错:springboot Failed to parse configuration class [Application]
查看>>