面试题

作者: 学学学q | 来源:发表于2021-04-22 22:41 被阅读0次
    1. 什么是大端和小端?
    • 大端模式:高位字节排放在内存的低地址端,低位字节排放在内存的高地址段。
    • 小端模式:低位字节排放在内存的低地址端,高位字节排放在内存的高地址端。
    1. 一个NSObject对象占用多少内存
    • 系统分配了16个字节给NSObject对象(通过malloc_size函数获得)
    • 但NSObject对象内部只使用了8个字节的空间(64bit环境下)
     NSObject *obj = [[NSObject alloc] init];
     NSLog(@"%zd", class_getInstanceSize([NSObject class]));
     NSLog(@"%zd", malloc_size((__bridge void *)obj));
    
    1. ImageIO学习
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        
        UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(60, 120, [UIScreen mainScreen].bounds.size.width - 120, 160)];
        [self.view addSubview:iv];
        
    //
    //    UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"11.jpeg" ofType:nil]];
    //    NSData *data = UIImageJPEGRepresentation(image, 1.0);
    //    SDImageFormat type = [NSData sd_imageFormatForImageData:data];
    //    NSLog(@"%zd", type);
    //
    //    NSString *typeStr = (NSString *)[NSData sd_UTTypeFromImageFormat:type];
    //    NSLog(@"%@", typeStr);
        
    //    CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
    
        NSString *path = [[NSBundle mainBundle] pathForResource:@"show.gif" ofType:nil];
        NSURL *url = [NSURL fileURLWithPath:path];
    
        CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
    
        long count = CGImageSourceGetCount(source);
        NSLog(@"图片个数%ld", count);
        //获取第几张图片
        CGImageRef firstImage = CGImageSourceCreateImageAtIndex(source, 23, NULL);
    
        NSArray *arr = CFBridgingRelease(CGImageSourceCopyTypeIdentifiers());
        NSLog(@"支持的类型\n%@", arr);
    
        NSString *type = CFBridgingRelease(CGImageSourceGetType(source));
        NSLog(@"所加载图片的类型为:%@", type);
    
        // 获取某一帧图片的缩略图
        CGImageRef thumbnailImage = CGImageSourceCreateThumbnailAtIndex(source, 0, NULL);
        NSLog(@"%@", thumbnailImage);
        
        CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
        
        NSInteger orientationValue = 1;
        CFTypeRef val = CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight);
        // 图片的高度
        if (val) CFNumberGetValue(val, kCFNumberLongType, &_height);
        val = CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth);
        // 图片的宽度
        if (val) CFNumberGetValue(val, kCFNumberLongType, &_width);
        val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation);
        // 图片的方向
        if (val) CFNumberGetValue(val, kCFNumberNSIntegerType, &orientationValue);
        
        CFRelease(source);
        _orientation = (CGImagePropertyOrientation)orientationValue;
        
        
        iv.image = [UIImage imageWithCGImage:thumbnailImage];
    }
    

    相关文章

      网友评论

          本文标题:面试题

          本文链接:https://www.haomeiwen.com/subject/jxaxrltx.html