iOS 中计算图片资源的大小方式

长 * 宽*scale * scale
scale 是根据屏幕大小所获取的缩放因子

if SD_WATCH

if ([[WKInterfaceDevice currentDevice] respondsToSelector:@selector(screenScale)])

elif SD_UIKIT

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])

elif SD_MAC

if ([[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)])

endif

{
    // [email protected] -> 8
    if (key.length >= 8) {
        // Fast check
        BOOL isURL = [key hasPrefix:@"http://"] || [key hasPrefix:@"https://"];
        for (NSNumber *scaleFactor in SDImageScaleFactors()) {
            // @2x. for file name and normal url
            NSString *fileScale = [NSString stringWithFormat:@"@%@x.", scaleFactor];
            if ([key containsString:fileScale]) {
                scale = scaleFactor.doubleValue;
                return scale;
            }
            if (isURL) {
                // %402x. for url encode
                NSString *urlScale = [NSString stringWithFormat:@"%%40%@x.", scaleFactor];
                if ([key containsString:urlScale]) {
                    scale = scaleFactor.doubleValue;
                    return scale;
                }
            }
        }
    }
}
return scale;

}

你可能感兴趣的:(iOS 中计算图片资源的大小方式)