- 什么是大端和小端?
- 大端模式:高位字节排放在内存的低地址端,低位字节排放在内存的高地址段。
- 小端模式:低位字节排放在内存的低地址端,高位字节排放在内存的高地址端。
- 一个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));
- 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];
}