iOS 裁剪图片
来源:互联网 发布:有什么sm软件 编辑:程序博客网 时间:2024/06/08 02:15
// 裁剪正方形self.photoView.contentMode = UIViewContentModeScaleAspectFill;self.photoView.clipsToBounds = YES;/* * 裁剪图片中间正方形 */- (UIImage *)clipsMaxSquareWithImage:(UIImage *)image{ CGFloat imageW = image.size.width; CGFloat imageH = image.size.height; CGRect clipsRect; CGFloat margin = imageW - imageH; if (margin > 0) { clipsRect = CGRectMake(margin * 0.5, 0, imageH, imageH); } else { clipsRect = CGRectMake(0, abs(margin * 0.5), imageW, imageW); } CGImageRef cgRef = image.CGImage; CGImageRef imageRef = CGImageCreateWithImageInRect(cgRef, clipsRect); UIImage *thumbScale = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); image = thumbScale; return image;}/* * 按比例裁剪图片 */- (void)clipsScaleWithImage:(UIImage *)image{ CGFloat imageW = image.size.width; CGFloat imageH = image.size.height; CGFloat scale = 8 / 6; CGRect clipsRect; CGFloat rate = imageW / imageH; if (rate > scale) { CGFloat overW = imageW - (imageH / 6) * 8; clipsRect = CGRectMake(overW * 0.5, 0, imageW - overW, imageH); } else { CGFloat overH = imageH - (imageW / 6) * 8; clipsRect = CGRectMake(0, overH * 0.5, imageW, imageH - overH); } CGImageRef cgRef = image.CGImage; CGImageRef imageRef = CGImageCreateWithImageInRect(cgRef, clipsRect); UIImage *thumbScale = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); image = thumbScale; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; if (rate > scale) { imageView.frame = CGRectMake(0, 0, 400, 300); } else { imageView.frame = CGRectMake(0, 0, 300, 400); } [self.view addSubview:imageView];}
0 0
- ios裁剪图片
- iOS 裁剪图片
- IOS 裁剪图片
- ios图片裁剪
- ios 代码裁剪图片
- IOS 裁剪图片
- iOS 图片裁剪 缩放
- iOS 裁剪图片
- iOS裁剪图片
- iOS- 裁剪图片
- iOS-图片裁剪
- iOS 裁剪图片
- iOS图片裁剪
- ios 图片裁剪
- iOS 裁剪图片
- iOS-裁剪图片
- iOS-有关图片裁剪
- ios 图片裁剪
- Linux下MySql忘记 root密码的解决办法
- mac上安装配置maven
- Tian Ji -- The Horse Racing 2287 (好题 数学逻辑)
- Xen如何从虚拟机控制台返回到宿主机控制台
- 浅谈Android的三种数据持久化技术之文件存储
- iOS 裁剪图片
- 浅谈.net remoting 与webservice
- mongodb 聚合详解
- The connection to adb is down和no configs match configspec错误
- 你见过最好的幼儿园
- igrimaceV8.0.0 IG 一键新机 陌陌 Uber优步打针 平安易贷 滴滴 一号专车 饿了么 ios8 V8 ZTN(插件安装方式)
- 函数指针
- POJ 2533Longest Ordered Subsequence(DP最长上升子序列O(n^2)&&O(nlogn))
- php---mysql+ajax 无序列表(ul li)分页实现