1

我正在尝试获取该软件,以便在拍摄照片时,只有您在相机叠加层中看到的正方形内的图片部分显示为图片。后置摄像头工作正常,但是当我尝试用前置摄像头拍照时,由于某种原因,软件会缩小图片,这没有任何意义。任何关于我可能做错的想法都将不胜感激。

@IBAction func takePicture(sender: UIButton)
{
    let alertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
    let takePictureAction = UIAlertAction(title: "Take Picture", style: UIAlertActionStyle.Default)
    { (alertAction: UIAlertAction!) -> Void in
        self.isCameraPic = true
        let picker = UIImagePickerController()
        picker.delegate = self
        picker.sourceType = .Camera
        var f: CGRect
        f = picker.view.bounds
        let overlayIV = UIImageView(frame: f)

        overlayIV.image = UIImage(named: "cameraTarget")
        picker.cameraOverlayView = overlayIV
        self.presentViewController(picker, animated: true, completion: nil)
    }
    let chooseExistingPicture = UIAlertAction(title: "Use Existing", style: UIAlertActionStyle.Default) {(alertAction: UIAlertAction!) -> Void in
        self.isCameraPic = false
        let picker = UIImagePickerController()
        picker.delegate = self
        picker.sourceType = .PhotoLibrary
        self.presentViewController(picker, animated: true, completion: nil)
    }
    alertController.addAction(takePictureAction)
    alertController.addAction(chooseExistingPicture)
    alertController.view.tintColor = UIColor.blackColor()
    presentViewController(alertController, animated: true, completion: nil)
    let presentationController = alertController.popoverPresentationController
    presentationController?.sourceView = self.view
    presentationController?.sourceRect = CGRectMake(330, 210, 330, 210)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{

    var image = info[UIImagePickerControllerOriginalImage]

    let imageSize = image?.size
    if isCameraPic! == true && picker.cameraDevice == UIImagePickerControllerCameraDevice.Rear
    {
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(CGFloat(1140), CGFloat(1140)), false, 0.0)
        image?.drawAtPoint(CGPointMake(CGFloat(-400), CGFloat(-700)))
        image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
    }
    else if picker.cameraDevice == UIImagePickerControllerCameraDevice.Front
    {
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(CGFloat(4000), CGFloat(4000)), true, 0.0)
        image?.drawAtPoint(CGPointMake(CGFloat(0), CGFloat(0)))
        image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

    }
    CustomPicture.image = image as? UIImage;
    hasCustomImage = true
    changedImage = true
    dismissViewControllerAnimated(true, completion: nil)
}

请注意,前置摄像头曾经使用与后置摄像头相同的代码。我在调试期间对其进行了更改,因为我认为转换可能有所不同。这有点像转换被应用了两次,但我检查了它,它只被应用了一次。

谢谢你的帮助,
肖恩

4

1 回答 1

0

事实证明,我可以用较小的数字得到我想要的结果。前置摄像头的像素数必须与后置摄像头不同。无论如何,如果有人试图这样做,请尝试较小的数字而不是较大的数字。

于 2016-09-01T23:47:59.967 回答