+ (CGRect )scaleImage:(UIImage *)image toSize:(CGRect)newSize{
? ? float actualHeight = image.size.height;
? ? float actualWidth = image.size.width;
? ? float imgRatio = actualWidth/actualHeight;
? ? float maxRatio = newSize.size.width/newSize.size.height;
? ? if(imgRatio!=maxRatio){
? ? ? ? if(imgRatio < maxRatio){
? ? ? ? ? ? imgRatio = newSize.size.height/ actualHeight;
? ? ? ? ? ? actualWidth = imgRatio * actualWidth;
? ? ? ? ? ? actualHeight = newSize.size.height;
? ? ? ? }else{
? ? ? ? ? ? imgRatio = newSize.size.width / actualWidth;
? ? ? ? ? ? actualHeight = imgRatio * actualHeight;
? ? ? ? ? ? actualWidth = newSize.size.width;
? ? ? ? }
? ? }
? ? CGRect rect = CGRectMake(0.0,0.0, actualWidth, actualHeight);
? ? return rect;
}
圖片不失真方法:http://superdanny.link/2016/01/28/iOS-Upload-Image/
http://www.reibang.com/p/76f7eb00ef13
/*******************************************************************************************************************/
以下是涉及分辨率,對(duì)于圖片像素px 確保不失真救湖,方案
? ? CGFloatw =790;
? ? CGFloath =200;
? ? //point? = px / scale
? ? CGFloatscale = [[UIScreenmainScreen]scale];
? ? CGFloatnewW = w/scale;
? ? CGFloatnewH = h/scale;
? ? if (newW < [UIScreen mainScreen].bounds.size.width) {
? ? ? ? NSLog(@"iphone6+");
? ? ? ? //XR? scale = 2; newW? = 395點(diǎn)? 屏幕寬點(diǎn) = 414點(diǎn)
? ? ? ? //6S+ scale = 3; newW? = 250點(diǎn)? 屏幕寬點(diǎn) = 414點(diǎn)
? ? ? ? //對(duì)于分辨率來(lái)說(shuō), 無(wú)法全屏愧杯,因?yàn)槿習(xí)糯髨D片,因?yàn)閳D片小
? ? }else{
? ? ? ? NSLog(@"iphone6以下");
? ? ? ? // 6S scale = 2; newW? = 395點(diǎn)? 屏幕寬點(diǎn) = 375點(diǎn)
? ? ? ? // 對(duì)于分辨率來(lái)說(shuō),可以全屏鞋既,因?yàn)槿習(xí)s小圖片力九,因?yàn)閳D片大
? ? }