【问题标题】:Prompt iOS user to select JPEG to be processed by app提示iOS用户选择要由应用处理的JPEG
【发布时间】:2019-07-22 20:35:57
【问题描述】:

我已经在 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)
        }
    }
}

对应的术语和示例代码是什么/在哪里?

(感谢 Objective-C 示例)

【问题讨论】:

    标签: ios objective-c xcode


    【解决方案1】:

    iOS 中的 UIImagePickerController 视图控制器是允许用户从媒体库中选择图片的标准方式。有关这方面的 Apple 文档可在 UIImagePickerController. 获得。还有一个很好的教程,显示如何在 Picking images with UIImagePickerController in Swift 5 使用 UIImagePickerController。

    【讨论】:

    • 感谢参考+1
    【解决方案2】:

    这正是您要查找的内容:https://stackoverflow.com/a/41717882/2968456

    基本上你需要使用苹果内置的 UIImagePicker 框架。

    【讨论】:

    • 感谢参考+1
    【解决方案3】:

    Credit 主要参考其他答案,但这里是 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多