我想获取图像大小而不加载到内存中,我在目标c中找到但我需要在swift中可以任何人帮助我
#import <ImageIO/ImageIO.h>
- (CGSize)sizeOfImageAtURL:(NSURL *)imageURL {
CGSize imageSize = CGSizeZero;
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)imageURL, NULL);
if (source) {
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:(NSString
*)kCGImageSourceShouldCache];
CFDictionaryRef properties = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, 0, (CFDictionaryRef)options);
if (properties) {
NSNumber *width = [(NSDictionary *)properties objectForKey:(NSString *)kCGImagePropertyPixelWidth];
NSNumber *height = [(NSDictionary *)properties objectForKey:(NSString *)kCGImagePropertyPixelHeight];
if ((width != nil) && (height != nil))
imageSize = CGSizeMake(width.floatValue, height.floatValue);
CFRelease(properties);
}
CFRelease(source);
}
return imageSize; }