我使用AVFoundation生成视频.之后,我使用Photos Framework将视频写入照片库(之后获取PHAsset的实例).
我想为添加的PHAsset(视频的最后一帧)设置自定义缩略图,但无法找到解决方案.如何为添加的视频添加自定义缩略图?我想在我打开时在照片应用程序中看到我的自定义缩略图.
此外,我知道如何使用视频从视频中获取一些图像AVAssetImageGenerator,但我想在照片应用程序中看到我的缩略图.
我有一个要求,用户需要从库中的gif文件列表中获取gif.我试图获取图像和视频没有任何问题.但是当我用作kUTTypeGIF媒体时,它会因错误而崩溃:
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'没有可用的源0类型'
这是我的代码:
#import "ViewController.h"
#import <MobileCoreServices/MobileCoreServices.h>
@interface ViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
-(IBAction)btnChooseGif:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeGIF, nil]; // Here is the crash
[self presentViewController:imagePicker animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
}
@end
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?如果kUTTypeGIF此处不支持媒体,如何向用户显示所有gif文件列表以供选择?我只需要在UIImagePickerController中显示gif文件
我正在开发一个iOS应用程序,我需要像Instagram这样的画廊视图.我已经添加了图库视图,相机视图和视频视图,在拍摄图像后,它会保存到照片的自定义相册中.现在我想从自定义相册中检索这些图像并将其显示到Gallery的Collection视图.但是我在从自定义相册中检索这些图片时遇到困难.任何帮助将不胜感激.

编辑:我添加了用于创建自定义相册的PHPhotoLibrary,在此之前我添加了AssetsLibrary框架.
然后我创建了一个NSObject类(CustomAlbum),用于使用PHPhotoLibrary创建和管理自定义相册.
// CustomAlbum.h
#import <Foundation/Foundation.h>
#import <Photos/Photos.h>
@interface CustomAlbum : NSObject
//Creating album with given name
+(void)makeAlbumWithTitle:(NSString *)title onSuccess:(void(^)(NSString *AlbumId))onSuccess onError: (void(^)(NSError * error)) onError;
//Get the album by name
+(PHAssetCollection *)getMyAlbumWithName:(NSString*)AlbumName;
//Add a image
+(void)addNewAssetWithImage:(UIImage *)image toAlbum:(PHAssetCollection *)album onSuccess:(void(^)(NSString *ImageId))onSuccess onError: (void(^)(NSError * error)) onError;
//get the image using identifier
+ (void)getImageWithIdentifier:(NSString*)imageId onSuccess:(void(^)(UIImage *image))onSuccess onError: (void(^)(NSError * error)) onError;
@end
Run Code Online (Sandbox Code Playgroud)
// CustomAlbum.m
#import "CustomAlbum.h"
@implementation CustomAlbum
#pragma mark - PHPhoto
+(void)makeAlbumWithTitle:(NSString *)title onSuccess:(void(^)(NSString *AlbumId))onSuccess onError: (void(^)(NSError * …Run Code Online (Sandbox Code Playgroud) 这看起来似乎太容易了,也许这对我来说太困惑了......或许我太累了,无法理性思考.
我正在尝试使用imagePickerController获取用户从相册中选择的UIImage的位置.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *pic = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *data = UIImageJPEGRepresentation(pic, 0.01f);
UIImage *image1 = [UIImage imageWithData:data];
bookmarkImage.image = image1;
NSLog(@"new image size = %i", [data length]);
NSURL *url = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
4NSLog(@"%@",url);
ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *myAsset){
[myAsset valueForProperty:ALAssetPropertyLocation];
};
[self dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
现在,我尝试为ALAsset 调用valueForProperty是我遇到麻烦的地方.这是我得到的错误:
使用未声明的标识符'ALAssetPropertyLocation'.
请帮忙!这真的令人沮丧......我需要照片的位置......
我没有工作版本或想法如何通过PHPhotoLibrary或ALAssetsLibrary从您的相册中获取照片,并将其安装在uicollectionviewcell中,如在instagram中.我是客观c的新手:)
不安装 - 添加