iOS:等比压缩截图代码

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

将一幅图片按着需要的尺寸进行等比的压缩和放大,最后再截取需要尺寸部分,不知道说清楚没,反正就那意思吧!

+(UIImage *)comPRessImageWith:(UIImage *)image width:(float)width height:(float)height

{floatimageWidth =image.size.width;floatimageHeight =image.size.height;floatwidthScale = imageWidth /width;floatheightScale = imageHeight /height;//创建一个bitmap的context//并把它设置成为当前正在使用的contextUIGraphicsBeginImageContext(CGSizeMake(width, height));if(widthScale >heightScale) {

[image drawInRect:CGRectMake(0,0, imageWidth /heightScale , height)];

}else{

[image drawInRect:CGRectMake(0,0, width , imageHeight /widthScale)];

}//从当前context中创建一个改变大小后的图片UIImage *newImage =UIGraphicsGetImageFromCurrentImageContext();

[newImage retain];//使当前的context出堆栈UIGraphicsEndImageContext();returnnewImage;

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航