我已经在Android中完成此操作,但似乎找不到在iOS中执行此操作的任何信息。基本上:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/JPEG");
Intent i = Intent.createChooser(intent, "File");
startActivityForResult(i, CHOOSE_FILE_REQUESTCODE);
然后
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == CHOOSE_FILE_REQUESTCODE) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// The user picked a contact.
// The Intent's data Uri identifies which contact was selected.
// Do something with the contact here (bigger example below)
}
}
}
相应的术语和示例代码在哪里/什么地方?
(赞赏有目的的C示例)
答案 0 :(得分:1)
iOS中的UIImagePickerController视图控制器是允许用户从那里的媒体库中选择图片的标准方法。有关UIImagePickerController.的Apple文档,请访问Picking images with UIImagePickerController in Swift 5。还有一个很好的教程,展示了如何在Android record video into a circular buffer and storing it in RAM使用UIImagePickerController。
答案 1 :(得分:0)
这应该正是您要查找的内容:https://stackoverflow.com/a/41717882/2968456
基本上,您需要使用Apple内置的UIImagePicker框架。
答案 2 :(得分:0)
信用主要是供其他答案参考,但这是Objective-C示例代码:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
presentViewController:picker animated:YES completion:nil];
带有图像数据的回调:
/*============================================================================*/
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
/*============================================================================*/
{
[picker dismissViewControllerAnimated:YES completion:nil];
[picker release];
UIImage* image = [info objectForKey:UIImagePickerControllerEditedImage];
if (!image)
image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData* imgData = UIImageJPEGRepresentation(image, 1.0);
NSLog(@"Size of Image(bytes):%lu",(unsigned long)[imgData length]);
}
代理/ self
必须为:
UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>