我试图生成缩略图并将其保存到文件中。这是我的代码。
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:object[@"path"] options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
NSError *err = NULL;
CMTime requestedTime = CMTimeMake(1, 60); // To create thumbnail image
CGImageRef imgRef = [generator copyCGImageAtTime:requestedTime actualTime:NULL error:&err];
NSLog(@"err = %@, imageRef = %@", err, imgRef);
UIImage *thumbnailImage = [[UIImage alloc] initWithCGImage:imgRef];
CGImageRelease(imgRef);
NSString* path = [NSHomeDirectory() stringByAppendingString:@"/Documents/myImage.png"];
BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path
contents:nil attributes:nil];
if (!ok)
{
NSLog(@"Error creating file %@", path);
}
else
{
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[myFileHandle writeData:UIImagePNGRepresentation(thumbnailImage)];
[myFileHandle closeFile];
resolve(path);
}
但是我收到了这个错误:
Code=-11822 "Cannot Open" UserInfo={NSLocalizedDescription=Cannot Open, NSLocalizedFailureReason=This media format is not supported.}
有什么想法?