I’m developing a Camera App (with Xcode 12.2 & Swift 5.3.1.) by using UIImagepickerController.
In the Camera App, I want to put a semitransparent-image (image previously captured and make it semitransparent then overlaying) on the camera view (real-time view).
Now I can put a semitransparent-image on the camera view as shown in those figures, however the size of the semitransparent-image is not suitable.
The size of the semitransparent-image is too big (Figure 4 in the following link) than that of I want to display (Figure 3).
In the Camera App, I want to put a semitransparent-image (image previously captured and make it semitransparent then overlaying) on the camera view (real-time view).
Now I can put a semitransparent-image on the camera view as shown in those figures, however the size of the semitransparent-image is not suitable.
The size of the semitransparent-image is too big (Figure 4 in the following link) than that of I want to display (Figure 3).
Could you tell me way to change (fit) the size of the semitransparent-image?In concretely, I want to change the size of image that displayed by “UIImageView(image:UIImage(named: “default”))” in the following source codes.https://imgur.com/eUnBQzd
Code Block language import UIKit class ViewController: UIViewController ,UIImagePickerControllerDelegate ,UINavigationControllerDelegate{ @IBOutlet weak var previewView :UIImageView! let overlayView = UIImageView(image:UIImage(named: "default")) @IBAction func startCmamera (_sender : UIBarButtonItem) { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.camera){ let picker = UIImagePickerController() picker.sourceType = .camera picker.delegate = self overlayView.alpha = 0.4 picker.cameraOverlayView = overlayView self.present(picker, animated: true) } } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage previewView.contentMode = .scaleAspectFit previewView.image = image UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil) self.dismiss(animated: true) } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } }
Did you try to resize the frame of the overlayView ?
have a look here:
https://stackoverflow.com/questions/41154784/how-to-resize-uiimageview-based-on-uiimages-size-ratio-in-swift-3
have a look here:
https://stackoverflow.com/questions/41154784/how-to-resize-uiimageview-based-on-uiimages-size-ratio-in-swift-3