So, I've magnet out how to make a Zoom Effect with CATransform3DMakeScale(2.4, 2.4, 2.4) but now I have problems trying to save the Zoome preview Message (code as I do Zooming):
// init camera device
let captureDevice : AVCaptureDevice? = initCaptureDevice()
print("camera was initialized")
// Prepare output
initOutput()
if (captureDevice != nil) {
let deviceInput : AVCaptureInput? = initInputDevice(captureDevice: captureDevice!)
if (deviceInput != nil) {
initSession(deviceInput: deviceInput!)
// Preview Size
let previewLayer: AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: self.session)
previewLayer.frame = self.view.bounds
previewLayer.transform = CATransform3DMakeScale(2.4, 2.4, 2.4)
imagePreviewScale = previewLayer.contentsScale
self.view.layer.addSublayer(previewLayer)
self.session?.startRunning()
Now i tried to save the previewed Zoomed image like so:
let videoConnection : AVCaptureConnection? = self.imageOutput?.connection(withMediaType: AVMediaTypeVideo)
if (videoConnection != nil) {
videoConnection?.videoScaleAndCropFactor = imagePreviewScale
self.imageOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: { (imageDataSampleBuffer, error) -> Void in
if (imageDataSampleBuffer != nil) {
// Capture JPEG
let imageData : NSData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer) as NSData
// JPEG
let image = UIImage(data: imageData as Data)
and added the line
imagePreviewScale = previewLayer.contentsScale
But still nothing happens, please anyone can tell me how to save The Exactly Zoomed picture?