gpt4 book ai didi

ios - 允许编辑 UIImagePickerViewController 无法选择 2 个不同的图像

转载 作者:行者123 更新时间:2023-11-30 12:00:41 24 4
gpt4 key购买 nike

我有一个带有 2 个 UIImageViews 和 2 个按钮的 View ,以便使用 UIImagePickerViewController 选择 2 张不同的图片。它实际上工作得很完美,但我想缩放图像并最终在 UIImageViews 中显示图像的选定部分。

允许在缩放时正确进行编辑,并且显然“允许编辑”图片,但最终选定的部分不会出现在 UIImageViews 中。

代码在这里。怎么了?

import UIKit

var fotoUnoEscogida = UIImage()
var fotoDosEscogida = UIImage()


class viewControllerDso : UIViewController, UIImagePickerControllerDelegate ,UINavigationControllerDelegate, UITextViewDelegate{


//Images
@IBOutlet weak var imageView1: UIImageView!
@IBOutlet weak var imageView2: UIImageView!
//TextViews
@IBOutlet weak var textViewExteriorUno: UITextView!
@IBOutlet weak var textViewExteriorDos: UITextView!
@IBOutlet weak var textViewInteriorUno: UITextView!
@IBOutlet weak var textViewInteriorDos: UITextView!




var imagePicker = UIImagePickerController()
var imagePicked = 0

override func viewDidLoad() {
super.viewDidLoad()



}


@IBAction func chooseImage(sender: UIButton) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){
print("chooseImage Button capture ")

imagePicked = sender.tag
imagePicker.delegate = self
imagePicker.sourceType = .SavedPhotosAlbum
imagePicker.allowsEditing = true

self.presentViewController(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

if imagePicked == 1 {

imageView1.contentMode = UIViewContentMode.ScaleAspectFill
imageView1.image = pickedImage

imageView1.layer.masksToBounds = true
imageView1.layer.borderWidth = 6
imageView1.layer.cornerRadius = imageView1.layer.frame.height/6
imageView1.layer.borderColor = UIColor.purpleColor().colorWithAlphaComponent(0.2).CGColor




} else if imagePicked == 2 {


imageView2.contentMode = UIViewContentMode.ScaleAspectFill
imageView2.image = pickedImage

imageView2.layer.masksToBounds = true
imageView2.layer.borderWidth = 6
imageView2.layer.cornerRadius = imageView2.layer.frame.height/6
imageView2.layer.borderColor = UIColor.purpleColor().colorWithAlphaComponent(0.2).CGColor




}
dismissViewControllerAnimated(true, completion: nil)
}


}

最佳答案

didFinishPickingMediaWithInfo中而不是

let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

使用

let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage

关于ios - 允许编辑 UIImagePickerViewController 无法选择 2 个不同的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47275964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com