我正试图通过ALAssetsLibrary访问iPhone的相册库。我成功访问相册并获取设备上每个图像的资产URL。我的测试是,在获得所有图像后,上传到我的网络服务器也运行良好。 我也试图获取视频文件并执行相同的过程,即将视频文件上传到我的服务器。这是问题,我不知道如何访问视频指针二进制文件,就像我使用UIImageJPEGRepresentation为图像做的那样,并发送到我的HTTP代码?
-(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];
}
有人能遇到这个解决,请指导我!
答案 0 :(得分:6)
您可以使用ALAssetRepresentation的getBytes:fromOffset:length:error:
方法获取原始字节,如下所示:
uint8_t *bytes = malloc([representation size]);
NSError *error = nil;
NSUInteger length = [representation getBytes:bytes fromOffset:0 length:[representation size] error:&error];