//
//  OJAUtilMethod.m
//  OJAKitDemo
//
//  Created by luxiaoming on 2017/8/14.
//  Copyright © 2017年 luxiaoming. All rights reserved.
//

#import "OJAUtilMethod.h"

@implementation OJAUtilMethod


/**
 将图片按原来的宽高比缩放到maxSize
 其实就是按aspectFit方式缩放后的大小
 */
+ (CGSize)aspectFitSizeForOriginalSize:(CGSize)size withinMaxSize:(CGSize)maxSize {
    if (size.width <= 0.01 || size.height <= 0.01 || maxSize.width < 0.01 || maxSize.height <= 0.01) {
        return CGSizeZero;
    }
    //注意，这里要比较size和max的宽高比，而不是具体的宽高
    if (size.width / size.height > maxSize.width / maxSize.height) {
        return CGSizeMake(maxSize.width, maxSize.width * size.height / size.width);
    } else {
        return CGSizeMake(maxSize.height * size.width / size.height, maxSize.height);
    }
    
}


@end
