- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当我使用 ALAssetLibrary 获取照片时,对于某些图像,AssetRepresentation.size 变为零,这不会在我的 ImageView 上生成图像。这是代码:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqual:self.groupName]) {
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop){
//Get the asset type
NSString *assetType = [result valueForProperty:ALAssetPropertyType];
if ([assetType isEqualToString:ALAssetTypePhoto]) {
NSLog(@"Photo Asset");
}
//Get URLs for the assets
NSDictionary *assetURLs = [result valueForProperty:ALAssetPropertyURLs];
NSUInteger assetCounter = 0;
for (NSString *assetURLKey in assetURLs) {
assetCounter++;
}
//Get the asset's representation object
ALAssetRepresentation *assetRepresentation = [result defaultRepresentation];
//From this asset representation, we take out data for image and show it using imageview.
dispatch_async(dispatch_get_main_queue(), ^(void){
CGImageRef imgRef = [assetRepresentation fullResolutionImage];
//Img Construction
UIImage *image = [[[UIImage alloc] initWithCGImage:imgRef] autorelease];
NSLog(@"before %@:::%lld", [image description], [assetRepresentation size]); //Prints '0' for size
if((image != nil)&& [assetRepresentation size] != 0){
//display in image view
}
else{
// NSLog(@"Failed to load the image.");
}
});
}];
}
}failureBlock:^(NSError *error){
NSLog(@"Error retrieving photos: %@", error);
}];
[library release];
请帮助。我在这里做错了什么?我应该如何获取图像?
最佳答案
乔·史密斯是对的!你过早地释放图书馆。一旦 AssetLibrary 被释放,所有的 Assets 对象都会随之消失。并且由于这些枚举是 block 代码,因此AssetLibrary的释放将在读取过程中的某个地方执行。
我建议您在应用程序委托(delegate)中创建您的 assetLibrary 以使其保持事件状态,并且仅在您从 ALAssetLibrary 收到更改通知 ALAssetsLibraryChangedNotification 时才重置它
关于iphone - 获取照片 alassetlibrary asset representation size zero,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11772193/
我创建了一个应用程序,使用 ALAssetLibrary 从 iPhone 照片文件夹中获取图像。 我可以在不使用定位服务的情况下使用 AlAssetLibrary 检索文件吗?我怎样才能避免 AlA
我正在尝试挑选一些相机胶卷元数据。当我枚举 Assets 时,我似乎无法检索任何信息并获得一个空数组。有没有我错过的步骤? 我的代码: assets = [[NSMutableArray array]
我试图通过这段代码使用 ALAssetLibrary 加载应用程序中的所有文件(音频、视频和图像): ALAssetsLibrary *library = [[ALAssetsLibrary allo
我想从 MPMoviePlayer 的图库中获取我正在播放的视频名称,我已经搜索了很多关于获取从图库中播放的视频名称的信息,但我总是只得到路径,我能得到视频的名称吗?我应该怎么办做?任何想法?我只看到
我以前用过 ALAsset,它适用于 iOS7~iOS9 的大多数用户(大约 100K)。 但一些用户提示它在 i6 设备、ios8/ios9 上只显示部分照片。 (也许 1% 有这个问题,我不确定。
我正在尝试使用 Marin Todorov 的 ALAssetsLibrary+CustomPhotoAlbum 将我生成的一些图像保存到使用 ALAssetLibrary 的相册中。但是,大多数时候
我正在尝试显示照片库中的图像以及时间戳(创建或修改时间)。我使用以下代码获取了图像。我怎样才能正确得到他们的时间戳?这是代码: -(void)getAllPictures{ imageArray=[[
我正在开发相机应用。因为我需要在底部显示相机胶卷中的最后一张图像。我可以使用 ALAssetsLibrary 来做到这一点。如果相机胶卷中的最后一项是视频,我需要显示该视频的第一个缩略图。但是如何检测
我正在构建一个 iOS 应用程序,允许用户拍照并将其保存到自定义相册,该相册会使用相册中的照片填充应用程序中的 UICollectionView。我在网上找到了很多关于如何执行此操作的示例,但我无法解
我正在寻找计算 ALAssetLibrary 中项目数量的最快方法。至少在这一点上,我不关心里面有什么,我只关心里面有很多东西。 对于音乐/音乐视频来说很简单: MPMediaQuery* query
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: How can i avoid Location service in AlAssetLibrary? Ca
我有ViewController1和ViewController2。ViewController1是UICollectionView,它使用ASAssetLibrary将缩略图加载到UICollect
我使用 ALAssetLibrary 在我的模拟器中找到了一些关于图像的信息。我可以使用 NSLog 正确显示这些信息,但我不知道如何将这些信息保存在列表中。我使用的代码是这样的: NSMutable
我编写了一个简单的方法来从资源库中获取数据,该方法在 iOS4.3 上运行良好,但在 iOS5 中获取图像时会出现延迟。我应该怎么做才能加快 iOS 5 上的获取过程。 -(void)setImage
我想通过使用 ALAssetLibrary 显示视频的缩略图,为了将图库中的视频显示到我的应用程序,我从 ALAssetsFilter 中过滤了所有视频。 但我仍然在 ALAsset 类型的 Asse
我使用 ALAssetLibrary 获取 Assets 。有没有办法知道这张图片是风景还是肖像没有加载图片但只有 Assets ? [asset thumbnail] 返回 (75,75) 大小的图
当我使用 ALAssetLibrary 获取照片时,对于某些图像,AssetRepresentation.size 变为零,这不会在我的 ImageView 上生成图像。这是代码: ALAssetsL
我注意到即使我将 *stop BOOL 指针设置为 YES,我的枚举 block 也会被执行两次。我以为设置 *stop = YES 会在第一个之后停止? [lib enumerateGroupsWi
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。它不满足Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题
我是一名优秀的程序员,十分优秀!