1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- //
- // ProjectInfo_Apk_Image.m
- // UUTUtils
- //
- // Created by zhuge on 2017/12/27.
- // Copyright © 2017年 zhuge. All rights reserved.
- //
- #import "ProjectInfo_Apk_Image.h"
- @implementation ProjectInfo_Apk_Image
- - (ProjectInfo_Apk_Image *)initWithPath:(NSString *)path {
- self.path = path;
- self.image = [[NSImage alloc] initWithContentsOfFile:self.path];
-
- // 读取图片的长和高
- NSURL *imageFileURL = [NSURL fileURLWithPath:self.path];
- CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)imageFileURL, NULL);
- if (imageSource != NULL) {
- CGFloat width = 0.0f, height = 0.0f;
- CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
- if (imageProperties != NULL) {
- CFNumberRef widthNum = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
- if (widthNum != NULL) {
- CFNumberGetValue(widthNum, kCFNumberCGFloatType, &width);
- }
-
- CFNumberRef heightNum = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
- if (heightNum != NULL) {
- CFNumberGetValue(heightNum, kCFNumberCGFloatType, &height);
- }
-
- CFRelease(imageProperties);
- }
-
- self.width = width;
- self.height = height;
- }
-
- // 读取文件大小
- NSFileManager *man = [NSFileManager defaultManager];
- NSDictionary *attrs = [man attributesOfItemAtPath: self.path error: NULL];
- long result = [attrs fileSize];
- self.fileSize = result;
-
- return self;
- }
- @end
|