gpt4 book ai didi

ios - 怎么把ALAssets转换成NSData?

转载 作者:行者123 更新时间:2023-12-01 18:57:05 26 4
gpt4 key购买 nike

我需要将文件从ALAssetsLibrary转换为NSData,但是我得到的是nil。

我用这个代码

 path = file:///assets-library://asset/asset.mp4?....
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
NSData *dates = [NSData dataWithContentsOfURL: url];

如何正确执行此操作?

最佳答案

希望这对你有帮助

 ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:[[self.imagedata objectAtIndex:i] valueForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset)
{
ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];//this is NSData may be what you want
[data writeToFile:photoFile atomically:YES];//you can save image later
}
failureBlock:^(NSError *err) {
NSLog(@"Error: %@",[err localizedDescription]);
}];

关于ios - 怎么把ALAssets转换成NSData?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26057394/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com