【发布时间】:2014-02-23 23:27:36
【问题描述】:
我需要在不加载或下载的情况下读取图像的属性。事实上,我已经实现了一个简单的方法,它使用 CGImageSourceCreateWithUrl 来完成这个。 我的问题是它总是返回错误,因为 imageSource 似乎为空。那么我能做些什么来修复它呢? 在 NSURL 对象中,我传递如下网址: “http://www.example.com/wp-content/uploads/image.jpg”还有用于检索手机内图像的 ALAssets 库 ID,例如“assets-library://asset/asset.JPG?id=E5F41458-962D-47DD-B5EF-E606E2A8AC7A&ext=JPG”。 这是我的方法:
-(NSString *) getPhotoInfo:(NSString *)paths{
NSString *xmlList = @“test”;
NSURL * imageFileURL = [NSURL fileURLWithPath:paths];
NSLog(@"imageFileURL %@", imageFileURL);
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)(imageFileURL), NULL);
if (imageSource == NULL) {
// Error loading image
NSLog(@"Error loading image");
}
CGFloat width = 0.0f, height = 0.0f;
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
NSLog(@"image source %@", imageSource);
return xmlList;
}
我已经看到这篇文章试图修复它,但似乎没有任何效果:
- CGImageSourceRef imageSource = CGImageSourceCreateWithURL returns NULL
- CGImageSourceCreateWithURL with authentication
- accessing UIImage properties without loading in memory the image
在我的项目中启用了 ARC。
谢谢
【问题讨论】:
标签: objective-c nsurl cgimagesource