ProjectInfo_Apk_Image.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // ProjectInfo_Apk_Image.m
  3. // UUTUtils
  4. //
  5. // Created by zhuge on 2017/12/27.
  6. // Copyright © 2017年 zhuge. All rights reserved.
  7. //
  8. #import "ProjectInfo_Apk_Image.h"
  9. @implementation ProjectInfo_Apk_Image
  10. - (ProjectInfo_Apk_Image *)initWithPath:(NSString *)path {
  11. self.path = path;
  12. self.image = [[NSImage alloc] initWithContentsOfFile:self.path];
  13. // 读取图片的长和高
  14. NSURL *imageFileURL = [NSURL fileURLWithPath:self.path];
  15. CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)imageFileURL, NULL);
  16. if (imageSource != NULL) {
  17. CGFloat width = 0.0f, height = 0.0f;
  18. CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
  19. if (imageProperties != NULL) {
  20. CFNumberRef widthNum = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
  21. if (widthNum != NULL) {
  22. CFNumberGetValue(widthNum, kCFNumberCGFloatType, &width);
  23. }
  24. CFNumberRef heightNum = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
  25. if (heightNum != NULL) {
  26. CFNumberGetValue(heightNum, kCFNumberCGFloatType, &height);
  27. }
  28. CFRelease(imageProperties);
  29. }
  30. self.width = width;
  31. self.height = height;
  32. }
  33. // 读取文件大小
  34. NSFileManager *man = [NSFileManager defaultManager];
  35. NSDictionary *attrs = [man attributesOfItemAtPath: self.path error: NULL];
  36. long result = [attrs fileSize];
  37. self.fileSize = result;
  38. return self;
  39. }
  40. @end