我有2 UIImageViews
和2个按钮的视图,以便用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)
}
}
答案 0 :(得分:2)
didFinishPickingMediaWithInfo
中的而不是
let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
使用
let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage
答案 1 :(得分:0)
更新Swift 5.2
RUN C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache `
--installPath C:\BuildTools `
--add Microsoft.VisualStudio.Workload.AzureBuildTools `
# <append the line below>
--add Microsoft.VisualStudio.Workload.NetCoreBuildTools `