- (UIImage *)imagecutWithRect:(CGRect)rect {

    CGImageRef subImageRef = CGImageCreateWithImageInRect(self.CGImage, rect);

    CGRect smallRect = CGRectMake(, , CGImageGetWidth(subImageRef), CGImageGetHeight(subImageRef));

    // 开启图形上下文
UIGraphicsBeginImageContext(smallRect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextDrawImage(context, smallRect, subImageRef); UIImage * image = [UIImage imageWithCGImage:subImageRef]; // 关闭图形上下文
UIGraphicsEndImageContext(); CGImageRelease(subImageRef); return image;
}

使用

- (UIImageView *)imageView {
if (_imageView == nil) {
self.imageView = [[UIImageView alloc] init];
self.imageView.backgroundColor = [UIColor redColor]; UIImage * image = [UIImage imageNamed:@"1.jpg"];
// 截取原图中间300*300
CGFloat cutImageWH = ;
CGFloat cutImage_x = (image.size.width - ) / ;
CGFloat cutImage_y = (image.size.height - ) / ; self.imageView.image = [image imagecutWithRect:CGRectMake(cutImage_x, cutImage_y, cutImageWH, cutImageWH)];
} return _imageView;
}

github地址: https://github.com/mancongiOS/UIImage.git

最新文章

  1. tomcat输出servlet-api.jar - jar not loaded 解决办法
  2. Oracle 支持在具有 DHCP 分配的 IP 地址的系统上进行安装
  3. oracle数据库高级应用之《自动生成指定表的insert,update,delete语句》
  4. POJ2531Network Saboteur(DFS+剪枝)
  5. markdown 书写表格
  6. android 应用架构随笔六(Loading加载页面)
  7. sql server 快捷键
  8. CSS3中的网格
  9. HDU 4597 Play Game (DP,记忆化搜索,博弈)
  10. BAE 环境下配置 struts2 + spring + hibernate(SSH)(三)spring&hibernate
  11. 移动web开发常用属性
  12. Maven中解决依赖冲突的问题
  13. Java进阶篇(二)——抽象类、内部类
  14. MongoDB最佳实践中文手册
  15. 使用 MapTiler 进行地图切片
  16. mysql面试题
  17. 版本控制,django缓存,跨域问题解决
  18. vue 加载更多
  19. Qt的Radio Button(单选按钮)
  20. Linux 中计划任务-at-cron

热门文章

  1. linux-dns服务器搭建
  2. 0003--Weekly Meeting on 10th April and 17th April, 2015
  3. jdbc autoReconnect=true 参数设置导致 slow log 爆表。
  4. 算法:Astar寻路算法改进
  5. 一个App完成入门篇(五)- 完成新闻页面
  6. Java提高配(三七)-----Java集合细节(三):subList的缺陷
  7. TCP Server—Linux
  8. 使用Guava提供的transform批量转换
  9. as3 Loader 加载资源后内存泄露无法释放的问题。
  10. 异步编程之Javascript Promises 规范介绍