截屏,如何截取自定义范围的图片
2015-06-17 18:46
162 查看
CGRect rect =self.view.frame;
// UIGraphicsBeginImageContext(rect.size);
个人认为使用这个就相当于UIGraphicsBeginImageContextWithOptions(rect.size, NO,
1.0);
选择NO,其他区域透明 选择YES,其他区域不透明,可以看到黑色区域
1.0这个代表缩放倍数为1.0倍
UIGraphicsBeginImageContextWithOptions(rect.size,NO,
2.0);
CGContextRef context =UIGraphicsGetCurrentContext();
[self.view.layerrenderInContext:context];
UIImage *img =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//你自定义区域的起点,宽,高;
CGRect rect1 =CGRectMake(0,
(100)*2,SCREEN_WIDTH*2
, (SCREEN_HEIGHT/2-20)*2);//你要截取的是CGRectMake(0,
100, SCREEN_WIDTH , (SCREEN_HEIGHT/2-20))这个范围,但是因为上面是2.0放大了,所以你自定义截取的范围都要放大2倍。
之所以本人要放大两倍,是因为1.0的时候,出现了图片不清晰的情况
UIImage * imgeee = [UIImageimageWithCGImage:CGImageCreateWithImageInRect([imgCGImage],
rect1)];
//imgeee就是你所需要的区域截图
// UIGraphicsBeginImageContext(rect.size);
个人认为使用这个就相当于UIGraphicsBeginImageContextWithOptions(rect.size, NO,
1.0);
选择NO,其他区域透明 选择YES,其他区域不透明,可以看到黑色区域
1.0这个代表缩放倍数为1.0倍
UIGraphicsBeginImageContextWithOptions(rect.size,NO,
2.0);
CGContextRef context =UIGraphicsGetCurrentContext();
[self.view.layerrenderInContext:context];
UIImage *img =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//你自定义区域的起点,宽,高;
CGRect rect1 =CGRectMake(0,
(100)*2,SCREEN_WIDTH*2
, (SCREEN_HEIGHT/2-20)*2);//你要截取的是CGRectMake(0,
100, SCREEN_WIDTH , (SCREEN_HEIGHT/2-20))这个范围,但是因为上面是2.0放大了,所以你自定义截取的范围都要放大2倍。
之所以本人要放大两倍,是因为1.0的时候,出现了图片不清晰的情况
UIImage * imgeee = [UIImageimageWithCGImage:CGImageCreateWithImageInRect([imgCGImage],
rect1)];
//imgeee就是你所需要的区域截图
相关文章推荐
- 从此爱上iOS Autolayout
- day06 Java基础
- mysql配置文件
- codeforces 321E Ciel and Gondolas 四边形不等式
- leetcode:Same Tree
- 第十五周项目二:二进制文件浏览器
- Hibernate框架简介
- Linux Socket 编程
- 分解和合并:Java 也擅长轻松的并行编程! 作者:Julien Ponge
- python爬虫 爬取知乎用户的用户信息
- Cannot proceed with delivery: an existing transporter instance is currently uploading this package
- MySQL Cluster(MySQL 集群) 初试
- 多线程04(单例,总结2)
- 第十五周项目一:用二进制文件处理学生成绩
- android listview局部刷新和模拟应用下载
- 鼠标击中测试码
- Joyent---Nodejs生产实践----(1)Design
- 分散精力
- 阅读《构建之法》第13-17章和《一个程序员的生命周期》有感
- ISAPI实现静态页面后并用c#实现分页