iPhone:使用库枚举时如何获取视频文件二进制文件?
我正试图通过图书馆访问iPhone的相册库。我成功访问相册并获取设备上每个图像的资源URL。我的测试是,在获得所有图像后,上传到我的web服务器也工作正常。 我还尝试获取视频文件并执行相同的过程,即将视频文件上载到我的服务器。问题是,我不知道如何访问视频指针二进制文件,就像我使用UIImageJPEGRepresentation对图像所做的那样,并发送到我的HTTP代码iPhone:使用库枚举时如何获取视频文件二进制文件?,iphone,Iphone,我正试图通过图书馆访问iPhone的相册库。我成功访问相册并获取设备上每个图像的资源URL。我的测试是,在获得所有图像后,上传到我的web服务器也工作正常。 我还尝试获取视频文件并执行相同的过程,即将视频文件上载到我的服务器。问题是,我不知道如何访问视频指针二进制文件,就像我使用UIImageJPEGRepresentation对图像所做的那样,并发送到我的HTTP代码 -(void) assetsEmumeration { void (^assetEnumerator)(struct AL
-(void) assetsEmumeration {
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL) {
NSLog(@"See Asset: %@", result);
[assetArray addObject:result];
// get image url
NSURL *url = [[result defaultRepresentation] url];
NSString *urlInStr = [NSString stringWithFormat:@"%@",url];
NSData *imgData = UIImageJPEGRepresentation ([UIImage imageWithCGImage:[result thumbnail]], 90);
HttpUpload (imgData);
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
}
[self.activity stopAnimating];
[self.activity setHidden:YES];
};
assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) {
NSLog(@"Failure: %@", [error localizedDescription]);
}];
assetArray = [[NSMutableArray array] retain];
}
有没有人碰到这个问题来解决,请指导我 您可以使用ALAssetRepresentation的方法获取原始字节,如下所示:
uint8_t *bytes = malloc([representation size]);
NSError *error = nil;
NSUInteger length = [representation getBytes:bytes fromOffset:0 length:[representation size] error:&error];
您可以使用ALAssetRepresentation的方法获取原始字节,如下所示:
uint8_t *bytes = malloc([representation size]);
NSError *error = nil;
NSUInteger length = [representation getBytes:bytes fromOffset:0 length:[representation size] error:&error];