判断图片等比例缩小


传入两个Image.size 然后来做比较

- (CGSize)setoriginW: (CGSize)imageWH setoriginH:(CGSize)originWH

{
    
    sizeWidth = originWH.width;  //图的宽
    sizeHeight = originWH.height; //图的高
    
    float imgwidth = imageWH.width;    //视图的宽
    float imgHeght = imageWH.height;   //视图的高
    
    NSLog(@"\nsizeWight==%f  \n sizeHeight = %f", sizeWidth,sizeHeight);
    
    
    if (sizeWidth >= imgwidth  && sizeHeight <= imgHeght) {
        
        newWidth = imgwidth;
        NSLog(@"0");
        newHeight = (imgHeght * sizeHeight) / sizeWidth;
    }
    
    else if(imgwidth <= sizeWidth && imgHeght >= sizeHeight){
        
        newHeight = imgHeght;
        NSLog(@"1");
        newWidth = imgHeght * sizeWidth / sizeHeight;
        
    }
    
    else if (sizeWidth >= imgwidth && sizeHeight >= imgHeght){
        
        if(sizeWidth / sizeHeight >= imgwidth / imgHeght)
        {
            newWidth = imgwidth;
            NSLog(@"2");
            newHeight = (imgHeght * sizeHeight) / sizeWidth;
        }
        
        if(sizeWidth / sizeHeight <= imgwidth / imgHeght)
        {
            newHeight = imgHeght;
            NSLog(@"3");
            newWidth = imgHeght * sizeWidth / sizeHeight;
        }
    }
    
    else
    {
        newWidth = sizeWidth;
        newHeight = sizeWidth;
        NSLog(@"4");
    }
    
    return  CGSizeMake(newWidth, newHeight);
    
}

你可能感兴趣的:(float)