iOS 图片比例缩放
2024-09-03 18:38:38
方法
//Resize image - (UIImage *)resizeImage:(UIImage *)image
withQuality:(CGInterpolationQuality)quality
rate:(CGFloat)rate
{
UIImage *resized = nil;
CGFloat width = image.size.width * rate;
CGFloat height = image.size.height * rate; UIGraphicsBeginImageContext(CGSizeMake(width, height));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, quality);
[image drawInRect:CGRectMake(0, 0, width, height)];
resized = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); return resized;
}
使用
UIImageView *theImageView = [[UIImageView alloc]init]; theImageView.frame = CGRectMake(0, 64, 320, 400); UIImage *aImage = [UIImage imageNamed:@"shenlin.png"]; UIImage *resizeImage = [self resizeImage:aImage withQuality:kCGInterpolationNone rate:0.2];
theImageView.image = resizeImage;
theImageView.frame = CGRectMake(0, 64, resizeImage.size.width, resizeImage.size.height);
NSLog(@"%@",NSStringFromCGSize(resizeImage.size)); [self.view addSubview:theImageView];
最新文章
- 线程Thread
- 【读书笔记】读《编写高质量代码—Web前端开发修炼之道》 - JavaScript原型继承与面向对象
- Unix环境编程之定时、信号与中断
- shutdown -s -t
- 利用Java API通过路径过滤上传多文件至HDFS
- Windows命令行(DOS命令)教程–2 (转载) http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_1.html
- Palindrome Subarrays
- 【原】spring boot在整合项目依赖的问题
- Python 执行字符串表达式函数(eval exec execfile)
- java文件创建、删除、读取、写入操作大全
- UIApplicationsharedApplication的常用使用方法
- JQuery 阻止事件冒泡
- URLconnection
- gitbook 入门教程之环境要求
- Proxmox VE登陆的时候提示没有有效的订阅You do not have a valid subscription for this server. Please visit www.proxmox.com to get a list of available options.
- 第16月第8天 NSInvocation存储 函数指针 va_arg lldb
- DDD领域模型系统的工作流(十四)
- linux系统安装pycharm环境
- Thrift 入门之helloWorld
- sql: Oracle 11g create table, function,trigger, sequence
热门文章
- [webpack] devtool里的7种SourceMap[转]
- 【UOJ 34】 #34. 多项式乘法 (FFT)
- Android之Fragment优点
- lightoj 1306 - Solutions to an Equation 扩展的欧几里得
- Java并发(十一):Condition条件
- [bzoj1021][SHOI2008]Debt 循环的债务 (动态规划)
- Powerdesigner打开工程提示打印错误 解决方法
- Spring依赖检查
- 计蒜之道 初赛 第三场 题解 Manacher o(n)求最长公共回文串 线段树
- UIBezierPath的使用(持续更新)