Mijick / CameraView

Camera made simple (SwiftUI)
MIT License
45 stars 6 forks source link

Cropped preview? #27

Open feelingsonice opened 1 week ago

feelingsonice commented 1 week ago

Is there a way to crop the preview and capture photos exactly like the cropped preview?

deden commented 1 week ago

@feelingsonice, I think you should implement Custom Preview for that

MCameraController()
    .outputType(.video)
    .gridVisible(false)
    .cameraPosition(.back) 
    .mediaPreviewScreen(CroppedPreview.init)
struct CroppedPreview: MCameraPreview {
    let capturedMedia: MijickCameraView.MCameraMedia
    let namespace: Namespace.ID
    let retakeAction: () -> ()
    let acceptMediaAction: () -> ()
// crop implementation
}
feelingsonice commented 6 days ago

@deden any tip on how to actually do that? I ran into a wall trying to do that with my own AVCaptureVideoPreviewLayer and couldn’t figure it out. Hence I’m now trying to see if there’s any third party libraries that could support this :(

FulcrumOne commented 3 days ago

@feelingsonice, were you able to solve your problem on your own?

If not please let me know, I'll try to create a demo project for you this week.

feelingsonice commented 3 days ago

I ended up not actually "cropping" the preview but fitFill a smaller rectangle on screen. When the user captures a photo, I crop it to the preview frame with something like this.

I think this works fine for my use case but would love to know how to actually crop out of curiosity. If it's a lot of work for you don't worry about it though :)

Thanks for the help!