赞
踩
UIGraphicsBeginImageContext创建了一个基于位图的上下文,并将其设置为当前上下文(context).
Void UIGraphicsBeginImageContext(CGSize size);
Void UIGraphicsBeginImageContextWithOptions(CGSizesize, BOOL opaque, CGFloat scale); //opaque透明开关,如果图形完全不用透明,设置YES优化位图存储;scale缩放因子
UIImage处理
1, 等比缩放
-(UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize{
UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize, image.size.height * scaleSize); //scaleSize为缩放比例, 创建基于位图的图形上下文
[image drawInRect:CGRectMake(0, 0, image.size.width*scaleSize, image.size.height *scaleSize )];//绘图
UIImage *scaledImage =UIGraphicsGetImageFromCurrentImageContext();
//获得图片
UIGraphicsEndImageContext();
//从当前堆栈中删除quartz2D绘图环境
return scaledImage; //返回缩放后的图片
}
2, 自定义大小
-(UIImag
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。