缩放图片代码
2016-05-26 15:09
260 查看
- ( UIImage *)imageWithImageSimple:( UIImage *)image scaledToSize:( CGSize )newSize{
// Create a graphics image context
// 创建一个bitmap的context
// 并把它设置成为当前正在使用的context
//Determine whether the screen is retina
if([[UIScreen mainScreen] scale] ==
3.0){
UIGraphicsBeginImageContextWithOptions(newSize,
NO, 3.0);
}else
if ([[UIScreen mainScreen] scale] ==
2.0){
UIGraphicsBeginImageContextWithOptions(newSize,
NO, 2.0);
}else{
UIGraphicsBeginImageContext(newSize);
}
// UIGraphicsBeginImageContext (newSize);
// Tell the old image to draw in this new context, with the desired
// new size
[image drawInRect : CGRectMake ( 0 ,
0 ,newSize. width ,newSize. height )];
// Get the new image from the context
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext ();
// End the context
UIGraphicsEndImageContext ();
// Return the new image.
return newImage;
}
// Create a graphics image context
// 创建一个bitmap的context
// 并把它设置成为当前正在使用的context
//Determine whether the screen is retina
if([[UIScreen mainScreen] scale] ==
3.0){
UIGraphicsBeginImageContextWithOptions(newSize,
NO, 3.0);
}else
if ([[UIScreen mainScreen] scale] ==
2.0){
UIGraphicsBeginImageContextWithOptions(newSize,
NO, 2.0);
}else{
UIGraphicsBeginImageContext(newSize);
}
// UIGraphicsBeginImageContext (newSize);
// Tell the old image to draw in this new context, with the desired
// new size
[image drawInRect : CGRectMake ( 0 ,
0 ,newSize. width ,newSize. height )];
// Get the new image from the context
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext ();
// End the context
UIGraphicsEndImageContext ();
// Return the new image.
return newImage;
}
相关文章推荐
- Java基本概念:集合类(Collection)List/Set/Map... 的区别和联系
- 使用第三方工具,将JavaBean对象或者List<JavaBean/String/Integer>或Set或Map对象转成JSON
- CI重定向:php(codeigniter)中如何重定向
- Java学习总结
- Java高级特性之泛型学习总结
- windows环境下搭建python机器学习开发环境
- PHP socket 绑定随机端口
- 《JAVA语言程序设计》(五)保留两位小数的操作
- 基于springMVC+shiro+Mybaits+ehcache缓存+Easyui的权限系统框架
- JAVA IO流的基本认识
- acm c++ 练习中出现的错误类型
- python【6】-函数式编程
- 使用springmvc中的RestTemplate向url地址post信息时乱码
- Myeclipse快捷键大全
- 关于Spring嵌套事务
- Java 单例模式详解
- Python FTP例子
- JDK动态代理实现原理(源码解读)
- MyEclipse启动加速与优化-----转载
- python中pop(),popitem()的整理