强制UIImagePickerController裁剪方形图像 [英] Force UIImagePickerController to Crop a Square Image

查看:130
本文介绍了强制UIImagePickerController裁剪方形图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何强制UIIImagePickerController裁剪方形图像?

How do we force UIIImagePickerController to crop a square image?

我已经搜遍了所有并且我找不到可靠的解决方案。 Thankyo

I have searched all over and I haven't found a solid solution. Thankyo

var imagePickerController: UIImagePickerController = UIImagePickerController();
imagePickerController.allowsEditing = true;
imagePickerController.delegate = self;
imagePickerController.sourceType = sourceType;



func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
    profilePictureSelected = true;

    profilePictureImageView.image = image;

    picker.dismissViewControllerAnimated(true, completion: nil);
}


推荐答案

你正确地做到了直到您收到代理回调,在回调中您需要指定它是您要使用的编辑图像。请注意,我在这里使用不同的委托方法。

You are doing it correctly up until you receive your delegate callback, within the callback you need to specify that it's the edited image that you want to use. Please note that i'm using a different delegate method here.

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
    if let chosenImage = info[UIImagePickerControllerEditedImage] as? UIImage {

        profilePictureSelected = true;

        profilePictureImageView.image = chosenImage;
    }
    picker.dismissViewControllerAnimated(true, completion: nil);
}

这篇关于强制UIImagePickerController裁剪方形图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆