前置摄像头图片的奇怪问题
Weird issue with Front facing camera pictures
我正在尝试获取该软件,以便在拍摄照片时,只有您在相机叠加层中看到的正方形内的照片部分显示为照片。后置摄像头工作正常,但当我尝试使用前置摄像头拍照时,出于某种原因,软件缩小了图片,而且没有任何意义。任何关于我可能做错了什么的想法都将不胜感激。
@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)
}
请注意,前置摄像头过去使用与后置摄像头相同的代码。我在调试期间更改了它,因为我认为转换可能有所不同。它的行为有点像转换被应用了两次,但我检查了它并且它只被应用了一次。
感谢您的帮助,
肖恩
事实证明,我可以用较小的数字得到我想要的结果。前置摄像头的像素数必须与后置摄像头的像素数不同。无论如何,如果有人试图这样做,请尝试使用较小的数字而不是较大的数字。
我正在尝试获取该软件,以便在拍摄照片时,只有您在相机叠加层中看到的正方形内的照片部分显示为照片。后置摄像头工作正常,但当我尝试使用前置摄像头拍照时,出于某种原因,软件缩小了图片,而且没有任何意义。任何关于我可能做错了什么的想法都将不胜感激。
@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)
}
请注意,前置摄像头过去使用与后置摄像头相同的代码。我在调试期间更改了它,因为我认为转换可能有所不同。它的行为有点像转换被应用了两次,但我检查了它并且它只被应用了一次。
感谢您的帮助,
肖恩
事实证明,我可以用较小的数字得到我想要的结果。前置摄像头的像素数必须与后置摄像头的像素数不同。无论如何,如果有人试图这样做,请尝试使用较小的数字而不是较大的数字。