从图库或相机中选择图像后,UIImage不显示

时间:2019-01-12 06:41:20

标签: ios swift xcode uiimage uiimagepickercontroller

我正在尝试从相机或图库中选择图像,然后在图像视图中将所选图像显示在屏幕上。但是它没有显示。

public void saveImage(Bitmap bitmap) {
        String filename = "dy/dx_wallpaper-" + System.currentTimeMillis();
        String url = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, filename, "Gradient Wallpaper");
        Toast.makeText(MainActivity.this, "Saved as " + url, Toast.LENGTH_SHORT).show();
    }

我想念什么?

enter image description here

就我而言,断点功能根本没有调用

3 个答案:

答案 0 :(得分:1)

我之前也遇到过同样的问题,并通过设置图像延迟来解决它,如下所示:

e.preventDefault()

希望这会有所帮助。

答案 1 :(得分:1)

确保已将UIImagePickerControllerDelegate添加到课程中,并设置了UIImagePickerController实例委托:

class PickerViewController: UIViewController, UIImagePickerControllerDelegate {
    var pickerController = UIImagePickerController()

    override func viewDidLoad() {
        super.viewDidLoad()
        pickerController.delegate = self
    }
}

此外,最好不要发送发送给该委托人的picker参数:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    ...

    picker.dismiss(animated: true, completion: nil)
}

答案 2 :(得分:1)

如果您的断点函数未在调用,那么我认为您尚未在viewDidLoad()中设置imagePicker委托

override func viewDidLoad() {
     super.viewDidLoad()
     imagePicker.delegate = self   
   }