Tag: alasset

如何从ALAssetRepresentation获取正确的旋转UIImage?

我正在尝试使用fullScreenImage方法从ALAssetRepresentation获取正确旋转的UIImage 。 我有几个testing照片在各种设备方向拍摄; 照片在照片应用中正确显示。 fullScreenImage的文档说: 在iOS 5和更高版本中,此方法返回完全裁剪,旋转和调整的图像 – 完全像用户在照片或图像select器中看到的一样。 要从CGImage创build一个正确旋转的UIImage对象,可以使用imageWithCGImage:scale:orientation:或initWithCGImage:scale:orientation:传递orientation和scale值。 鉴于文档,我的代码如下所示: ALAssetRepresentation *rep = [asset defaultRepresentation]; UIImage *img = [UIImage imageWithCGImage:[rep fullScreenImage] scale:[rep scale] orientation:[rep orientation]]; 但是由此产生的UIImage的旋转是错误的。 当我用UIImageOrientationUpreplace[rep orientation]时,对于所有的testing照片,图像都是正确的。 显然,我很犹豫要坚持这个“解决scheme”,因为它感觉像一个黑客。 我究竟做错了什么?

ALAssetsLibrary assetForURL:在iOS 8.1的“我的照片stream”中总是返回零

此代码在iOS 7中运行良好,但在iOS 8.1中,位于“我的照片stream”专辑中的所有资源都不在结果块内。 (failureBlock不叫。)普通的专辑和共享相册工作得很好。 我尝试从接受的答案: 尝试从assetForURL中分配__block ALAsset时出错:resultBlock: 也就是说,我持有一个对ALAssetsLibrary对象的引用,监听ALAssetsLibraryChangedNotification事件(这不是偶然发生的,但是哦)。我确定我的应用程序有权访问照片,我在无线上,我在我的tableView中看到了照片的缩略图。 只是当我尝试使用assetForURL:加载它们时assetForURL:它们总是零。 // example URL: assets-library://asset/asset.JPG?id=1ECB69B9-DC7A-45A7-B135-F43317D3412C&ext=JPG [self.library assetForURL:[NSURL URLWithString:url] resultBlock:^(ALAsset *asset) { NSLog(@"Asset: %@", asset); // nil 🙁 } failureBlock:^(NSError *error) { NSLog(@"Failure, wahhh!"); }]; 有没有人看到这个问题?

从ALAssetRepresentation生成自定义缩略图

我的主要问题是我需要获得一个ALAsset对象的缩略图。 我尝试了很多解决scheme,并search堆栈溢出了几天,由于这些约束,我发现的所有解决scheme都不适合我: 我不能使用默认的缩略图,因为它太less了; 我无法使用fullScreen或fullResolution图像,因为我在屏幕上有很多图像; 我不能使用UIImage或UIImageView来resize,因为这些加载fullResolution图像 我无法加载内存中的图像,我正在处理20Mpx图像; 我需要创build一个200×200像素版本的原始资产加载到屏幕上; 这是我附带的代码的最后一个迭代: #import <AssetsLibrary/ALAsset.h> #import <ImageIO/ImageIO.h> // … ALAsset *asset; // … ALAssetRepresentation *assetRepresentation = [asset defaultRepresentation]; NSDictionary *thumbnailOptions = [NSDictionary dictionaryWithObjectsAndKeys: (id)kCFBooleanTrue, kCGImageSourceCreateThumbnailWithTransform, (id)kCFBooleanTrue, kCGImageSourceCreateThumbnailFromImageAlways, (id)[NSNumber numberWithFloat:200], kCGImageSourceThumbnailMaxPixelSize, nil]; CGImageRef generatedThumbnail = [assetRepresentation CGImageWithOptions:thumbnailOptions]; UIImage *thumbnailImage = [UIImage imageWithCGImage:generatedThumbnail]; 问题是,所得到的CGImageRef既不是由方向转换的,也不是由指定的最大像素尺寸转换的; 我也试图find使用CGImageSourceresize的方法,但是: 资源url不能在CGImageSourceCreateWithURL: ; 我无法从ALAsset或ALAssetRepresentation提取CGDataProviderRef以与CGImageSourceCreateWithDataProvider:一起使用CGImageSourceCreateWithDataProvider: ; CGImageSourceCreateWithData:要求我将FullResolution或全屏资源存储在内存中才能正常工作。 我错过了什么? 是否有另一种方法从ALAsset或ALAssetRepresentation我缺less自定义缩略图? […]

从ALAsset url iOS获取videoNSData

我无法从我从ALAsset获取的URL中检索NSData 下面是我尝试的代码: – 我总是得到NSData为零。 NSData *webData = [NSData dataWithContentsOfURL:[asset defaultRepresentation].url]; 我也尝试过这样的事情 NSData *webData1 = [NSData dataWithContentsOfURL:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]]]; 我从ALAsset获得的url: – 资产库://asset/asset.MOV ID = 1000000116&EXT = MOV 我已经尝试了下面这个链接工作,但我需要不必要的写入到一个非常耗时的临时位置。 从ALAsset获取video 任何提示正确的方向将不胜感激。 等待你的回复