iOS 获取图片多少兆

- (NSString *)getBytesFromDataLength:(NSInteger)dataLength {

    NSString *bytes;

    if (dataLength >= 0.1 * (1024 * 1024)) {

        bytes = [NSString stringWithFormat:@"%0.1fM",dataLength/1024/1024.0];

    } else if (dataLength >= 1024) {

        bytes = [NSString stringWithFormat:@"%0.0fK",dataLength/1024.0];

    } else {

        bytes = [NSString stringWithFormat:@"%zdB",dataLength];

    }

    return bytes;

}

用法

NSData * imagedata=UIImageJPEGRepresentation(photos[0], 1);

NSInteger  length = imagedata.length/1024;

NSString *dataLength = [self getBytesFromDataLength:imagedata.length];

你可能感兴趣的:(iOS 获取图片多少兆)