我一直在努力寻找一种方法来启动带有方形实时视图的UIImagePickerController,并让它拍摄方形图片。我现在启动相机的代码在
之下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)
}
触发:
self.takePicture()
任何帮助都将不胜感激。
答案 0 :(得分:0)
你有没有看过cameraOverlayView
财产?这似乎是你在寻找的东西。
然后,您需要在收到图像后裁剪图像,因为叠加视图实际上不会进行裁剪。要裁剪,只需获取图片并根据cameraOverlayView
中“开场”的大小将其绘制为较小的矩形。