2
現在我是新手,但我想學習如何在swift中添加圓形蒙版。 現在我正在使用Xcode7.2.1,swift 2.1,但我不知道這一點。 而我正在開發這款相機應用程序,它使用https://github.com/imaginary-cloud/CameraManager作爲第三方庫。 在這裏,我想添加我的自定義圓形面具在相機上。 我在想誰能幫我弄到這個! 感謝如何在swift中在相機上添加圓形蒙版
現在我是新手,但我想學習如何在swift中添加圓形蒙版。 現在我正在使用Xcode7.2.1,swift 2.1,但我不知道這一點。 而我正在開發這款相機應用程序,它使用https://github.com/imaginary-cloud/CameraManager作爲第三方庫。 在這裏,我想添加我的自定義圓形面具在相機上。 我在想誰能幫我弄到這個! 感謝如何在swift中在相機上添加圓形蒙版
UIImagePickerController
有你可以用它來提供,這將作爲一個覆蓋一個自定義視圖的cameraOverlayView
財產。下面的示例創建一個正方形的疊加視圖。試用它來獲得你想要的。
@IBAction func takePhoto(sender: AnyObject) {
if !UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
return
}
var imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
//Create camera overlay
let pickerFrame = CGRectMake(0, UIApplication.sharedApplication().statusBarFrame.size.height, imagePicker.view.bounds.width, imagePicker.view.bounds.height - imagePicker.navigationBar.bounds.size.height - imagePicker.toolbar.bounds.size.height)
let squareFrame = CGRectMake(pickerFrame.width/2 - 200/2, pickerFrame.height/2 - 200/2, 200, 200)
UIGraphicsBeginImageContext(pickerFrame.size)
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context)
CGContextAddRect(context, CGContextGetClipBoundingBox(context))
CGContextMoveToPoint(context, squareFrame.origin.x, squareFrame.origin.y)
CGContextAddLineToPoint(context, squareFrame.origin.x + squareFrame.width, squareFrame.origin.y)
CGContextAddLineToPoint(context, squareFrame.origin.x + squareFrame.width, squareFrame.origin.y + squareFrame.size.height)
CGContextAddLineToPoint(context, squareFrame.origin.x, squareFrame.origin.y + squareFrame.size.height)
CGContextAddLineToPoint(context, squareFrame.origin.x, squareFrame.origin.y)
CGContextEOClip(context)
CGContextMoveToPoint(context, pickerFrame.origin.x, pickerFrame.origin.y)
CGContextSetRGBFillColor(context, 0, 0, 0, 1)
CGContextFillRect(context, pickerFrame)
CGContextRestoreGState(context)
let overlayImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
let overlayView = UIImageView(frame: pickerFrame)
overlayView.image = overlayImage
imagePicker.cameraOverlayView = overlayView
self.presentViewController(imagePicker, animated: true, completion: nil)
}
謝謝。但是,你有沒有在CameraManager中使用過?如果你有,我很高興知道如何在swift 2.0的相機中心添加定製圓形面具。再次感謝。 –
如何在完成圖像選取器代表中獲取圖像。我無法使用「信息[UIImagePickerControllerEditedImage]作爲?UIImage」 – Antony