I struggled to find a way to launch the UIImagePickerController with a square live view and get it to make a square picture. The code that I have now to start the camera is below
func takePicture() { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary){ println("Button capture") var imag = UIImagePickerController() imag.delegate = self imag.sourceType = UIImagePickerControllerSourceType.Camera //imag.mediaTypes = [kUTTypeImage]; imag.allowsEditing = false self.presentViewController(imag, animated: true, completion: nil) } } func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!) { let selectedImage : UIImage = image //var tempImage:UIImage = editingInfo[UIImagePickerControllerOriginalImage] as UIImage var newImage: UIImage = resizeImageWithImage(selectedImage, size: CGSize(width: 320, height: 568)) datImage.image=newImage let paths: NSArray = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) let documentsDir: NSString = paths.objectAtIndex(0) as NSString var dateFormat = NSDateFormatter() dateFormat.dateFormat = "yyyy-MM-dd-HH-mm-ss" let now:NSDate = NSDate(timeIntervalSinceNow: 0) let theDate = dateFormat.stringFromDate(now) //Make Photo URL self.photoURL = NSString(format: "/%@.png", theDate) //save resized image let pathToFullPhoto: NSString = documentsDir.stringByAppendingString(self.photoURL) let pngFull: NSData = UIImagePNGRepresentation(newImage) pngFull.writeToFile(pathToFullPhoto, atomically: true) self.dismissViewControllerAnimated(true, completion: nil) }
starts with: self.takePicture()
Any help would be appreciated.
source share