面试题

  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];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 推荐阅读:iOS开发——2019 最新 BAT面试题合集(持续更新中) 史上最全的iOS面试题及答案 iOS面试小...
    iOS开发之家阅读 5,526评论 1 15
  • 多线程、特别是NSOperation 和 GCD 的内部原理。运行时机制的原理和运用场景。SDWebImage的原...
    LZM轮回阅读 6,102评论 0 12
  • 最全的iOS面试题及答案 iOS面试小贴士 ———————————————回答好下面的足够了-----------...
    zweic阅读 7,606评论 0 73
  • 史上最全的iOS面试题及答案 iOS面试小贴士———————————————回答好下面的足够了----------...
    Style_伟阅读 7,098评论 0 35
  • iOS面试小贴士 ———————————————回答好下面的足够了------------------------...
    不言不爱阅读 6,220评论 0 7