Obj*_*c55 0 iphone photo objective-c ios
我有兴趣将文件(图像)从iPhone库/相机胶卷上传到远程Web服务器.我已经有一个脚本工作,将任何文件从手机上传到Web服务器.但是,我假设要从iPhone上传图像,我需要PATH来表示图像.一旦用户从相机胶卷中拾取所述图像,有什么办法可以做到这一点吗?即,如何获取在相机胶卷中选择的图像的文件路径?
我试着无济于事.
谢谢!
您将需要查看ALAssetsLibrary功能 - 这些功能可让您访问存储在iOS设备上的照片和视频库中的照片和视频.
具体来说,类似于:
ALAssetsLibrary *assets = [[ALAssetsLibrary alloc] init];
[assets enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) {
//the ALAsset should be one of your photos - stick it in an array and after this runs, use it however you need
}
}
failureBlock:^(NSError *error) {
//something went wrong, you can't access the photo gallery
}
];
Run Code Online (Sandbox Code Playgroud)
编辑
如果您使用的是UIImagePickerController而不是纯粹的编程方法,这会大大简化它:
在:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage];
//you can use UIImagePickerControllerOriginalImage for the original image
//Now, save the image to your apps temp folder,
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:@"upload-image.tmp"];
NSData *imageData = UIImagePNGRepresentation(img);
//you can also use UIImageJPEGRepresentation(img,1); for jpegs
[imageData writeToFile:path atomically:YES];
//now call your method
[someClass uploadMyImageToTheWebFromPath:path];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8006 次 |
| 最近记录: |