I've been looking to use some filters on my live camera feed, and have been following guidance of the AVCamFilter sample project to use a MTKView to render these live.
Within this project, there is some code in PreviewMetalView.swift (in setupTransform()) which scales the X and Y dimensions of the preview down, such that the entire preview is visible on screen:
I am, instead, trying to scale the image such that it is zoomed in, filling the view ("Aspect Fill", think like the Snapchat camera view), but, as I'm not familiar with scaling textures for MetalKit to render, I'm not entirely sure how I can scale this such that part of the preview goes beyond the view bounds. What is the best approach to this (I'm imagine this is just some simply multiplication that is alluding me, but would love any help I can get)
Within this project, there is some code in PreviewMetalView.swift (in setupTransform()) which scales the X and Y dimensions of the preview down, such that the entire preview is visible on screen:
Code Block if textureWidth > 0 && textureHeight > 0 { switch textureRotation { case .rotate0Degrees, .rotate180Degrees: scaleX = Float(internalBounds.width / CGFloat(textureWidth)) scaleY = Float(internalBounds.height / CGFloat(textureHeight)) case .rotate90Degrees, .rotate270Degrees: scaleX = Float(internalBounds.width / CGFloat(textureHeight)) scaleY = Float(internalBounds.height / CGFloat(textureWidth)) } } // Resize aspect ratio. resizeAspect = min(scaleX, scaleY) if scaleX < scaleY { scaleY = scaleX / scaleY scaleX = 1.0 } else { scaleX = scaleY / scaleX scaleY = 1.0 }
I am, instead, trying to scale the image such that it is zoomed in, filling the view ("Aspect Fill", think like the Snapchat camera view), but, as I'm not familiar with scaling textures for MetalKit to render, I'm not entirely sure how I can scale this such that part of the preview goes beyond the view bounds. What is the best approach to this (I'm imagine this is just some simply multiplication that is alluding me, but would love any help I can get)