Tag: alassetslibrary

如何从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似乎返回错误的我的照片数量

当我使用ALAssetsLibrary获取本地照片时,它工作正常。 但是,我删除了一些照片与'照片'应用程序我的应用程序崩溃。 崩溃信息是: "Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSOrderedSet enumerateObjectsAtIndexes:options:usingBlock:]: index 14 beyond bounds [0 .. 9]'".'14' 看起来,本地照片的数量仍然和befoore一样。 甚至在我退出我的应用程序并重新启动后,它仍然崩溃。 本地照片访问代码: dispatch_async(dispatch_get_main_queue(), ^ { @autoreleasepool { ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) { NSLog(@"error occour =%@", [myerror localizedDescription]); }; ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result, NSUInteger index, BOOL *stop) { if (result!=NULL) { if […]

如何使用MPMediaPickerController得到mp3的NSData?

我想从手机上传MP3到服务器,为此我使用MPMediaPickerController 。 得到MPMediaItem URL后,我想获得此url的NSData,但我在NSData中为空。 – (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection { [self dismissViewControllerAnimated:YES completion:nil]; MPMediaItem *item=[[mediaItemCollection items] objectAtIndex:0]; NSURL *url = [item valueForProperty: MPMediaItemPropertyAssetURL]; NSString *path = [NSString stringWithFormat:@"%@",url]; NSData *data = [[NSFileManager defaultManager] contentsAtPath:path]; } 我也试过 NSData *data = [NSData dataWithContentsOfURL:url]; 但数据为空,为什么? 我也试过不能从MPMediaItem(mp3歌曲)转换为NSData但没有得到结果。 任何人都可以指导我得到MP3的NSData。 提前致谢。

如何像ALAssetsLibrary一样使用PHPhotoLibrary

对于iOS9,不推荐使用ALAssetsLibrary 。 那么如何将它改为PHPPhotoLibrary而不是ALAssets呢? if (RecordedSuccessfully && recording == NO) { //—– RECORDED SUCESSFULLY —– NSLog(@"didFinishRecordingToOutputFileAtURL – success"); ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputFileURL]) { [library writeVideoAtPathToSavedPhotosAlbum:outputFileURL completionBlock:^(NSURL *assetURL, NSError *error) { if (error) { } }]; } //我已经试过这个,但没有工作 [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ PHAssetChangeRequest* createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:outputFileURL]; NSParameterAssert(createAssetRequest); } completionHandler:^(BOOL success, NSError *error) […]

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自定义缩略图? […]

iOS 8照片框架。 访问照片元数据

我正在寻找replaceALAssetsLibrary与我的应用程序中的照片框架。 我可以检索照片,collections集和资产来源(甚至把它们写回去),但没有看到任何地方访问照片的元数据(诸如{Exif},{TIFF},{GPS},等等…)。 ALAssetsLibrary有一个方法。 UIImagePickerController有一个方法。 照片必须有一个方法。 我看到,PHAsset有一个位置属性,这将为GPS字典,但我期待访问所有的元数据,其中包括,面孔,方向,曝光,ISO和吨更多。 目前苹果正处于testing阶段2.也许还有更多的API来? UPDATE ————————————————- —————– 没有正式的方法来使用照片API来做到这一点。 但是,您可以在下载图像数据后阅读元数据。 有两种方法可以使用PHImageManager或PHContentEditingInput来完成此操作。 PHContentEditingInput方法需要较less的代码,不需要导入ImageIO。 我把它包装在一个PHAsset类别中

iOS将照片保存在应用专用相册中

我正在创build一个iOS 5应用程序。 我想将照片保存到设备。 我想将照片保存到特定于我的应用的相册中,因此我需要创build相册,然后将照片保存到相册中。 我知道如何创build相册: ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library addAssetsGroupAlbumWithName:@"MY APP NAME" resultBlock:^(ALAssetsGroup *group) { //How to get the album URL? } failureBlock:^(NSError *error) { //Handle the error }]; 我现在要将照片添加到新相册,我该怎么做? 示例代码非常感谢!