获得app gallary之后裁剪方形图像

时间:2015-11-27 04:47:00

标签: swift swift2 uiimagepickercontroller

我很快就是新人。我做了简单的iPhone应用程序。使用此链接:http://www.oodlestechnologies.com/blogs/Open-Image-Gallery-and-Take-photo-in-Swift,我的应用程序运作完美。 我希望我的应用选择像Facebook或电报这样的可裁剪图像。 像这样:

enter image description here

我的代码:

private func showBottomActionSheet(){

    let chooseOptionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)

    let takePhotoAction = UIAlertAction(title: "Take Photo", style: .Default, handler: {
        (alert: UIAlertAction!) -> Void in
        self.openCamera()
    })
    let choosePhotoAction = UIAlertAction(title: "Choose Photo", style: .Default, handler: {
        (alert: UIAlertAction!) -> Void in
        self.openGallary()
    })

    let findImagesAction = UIAlertAction(title: "Find Images", style: .Default, handler: {
        (alert: UIAlertAction!) -> Void in
        print("Clicked Find Images")
    })

    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
        (alert: UIAlertAction!) -> Void in
        print("Cancelled")
    })

    chooseOptionMenu.addAction(takePhotoAction)
    chooseOptionMenu.addAction(choosePhotoAction)
    chooseOptionMenu.addAction(findImagesAction)
    chooseOptionMenu.addAction(cancelAction)

    self.presentViewController(chooseOptionMenu, animated: true, completion: nil)
}

private func openGallary()
{
    self.picker!.allowsEditing = false
    self.picker!.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
    presentViewController(picker!, animated: true, completion: nil)
}

private func openCamera()
{
    if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
        self.picker!.allowsEditing = false
        self.picker!.sourceType = UIImagePickerControllerSourceType.Camera
        self.picker!.cameraCaptureMode = .Photo
        presentViewController(self.picker!, animated: true, completion: nil)
    }else{
        let alert = UIAlertController(title: "Camera Not Found", message: "This device has no Camera", preferredStyle: .Alert)
        let ok = UIAlertAction(title: "OK", style:.Default, handler: nil)
        alert.addAction(ok)
        presentViewController(alert, animated: true, completion: nil)
    }
}

func imagePickerControllerDidCancel(picker: UIImagePickerController) {
    dismissViewControllerAnimated(true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){
    let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    self.choosenPhoto = chosenImage
    DefaultUser.setUserImage(chosenImage)
    dismissViewControllerAnimated(true, completion: nil)
}

我找到了客观的c代码,但没有找到swift 2的代码。 Plz,建议我。谢谢!

0 个答案:

没有答案