rlisenko / Icebreakers

2 stars 2 forks source link

Implement camera access #2

Open SuzGupta opened 5 months ago

SuzGupta commented 5 months ago

Allow user to take selfie directly from this app

possibly helpful reference: https://developer.apple.com/tutorials/sample-apps/capturingphotos-captureandsave

rlisenko commented 5 months ago

Yes, and find a way for the image output to be Square (this used to be an option in the native Camera app (no longer seeing it in the horizontal scroll of different image types in iOS17)

A square image output perfectly aligns with the Polaroid image it stacks on top.

ObjectiveCesar commented 5 months ago

Oh yes, there is... https://github.com/rlisenko/Icebreakers/assets/3286490/76bc8832-2b6a-40fc-bf45-cf72cf966933

I bet there is a way to pre-configure the camera view to use this aspect ratio by default and even only allow that one ratio.

rlisenko commented 5 months ago

It took me a while to understand why your Camera app had so many more choices than mine, I did not know the ^ button at the top center hid so many options in iOS17, great to know "Square" is still a choice, and yes, my memory is hazy from looking into this last March, but I'm pretty sure there was a way that the camera functionality can be restricted to only allow the Square choice, but will have to start researching that again!

rlisenko commented 5 months ago

Suz, your developer tutorial is way better than the ones I found last year off of Medium and the iPad's Playgrounds App. This will be great to read.

SuzGupta commented 5 months ago

Here's another one that looked interesting, mentioned in Dave Verwer's newsletter today. I wonder if we want to make a square mask? https://www.artemnovichkov.com/blog/remove-background-from-image-in-swiftui

rlisenko commented 5 months ago

I saw that in Dave Verwer's newsletter too and thought of the countless times I've removed backgrounds of Yorkies in Photoshop, but I'm hopefully past that for now, and couldn't think of a use-case for that article.

For this app, before we do any kind of image post processing, let's look for a setting within something like AVCapturePhotoOutput to specify the native camera's Square layout. Hopefully that's a 1 line dot notation option.

rlisenko commented 5 months ago
SuzGupta commented 5 months ago

Old but possibly useful: https://stackoverflow.com/questions/49609688/taking-a-square-photo-with-camera-app

rlisenko commented 5 months ago

Just noticed the Apple tutorial is a Playgrounds project rather than an Xcode one. If we run into the problems like I had porting over an older Playgrounds' Camera project into Xcode last year, we may need help understanding this sample code more deeply than what is shown in the tutorial.

SuzGupta commented 5 months ago

I have a working but imperfect implementation now (please delete the branch here and I will properly do this as a pull requests via my own fork, sorry, see Discord for another apologetic version of this same message). I based it on this: https://medium.com/@jakir/access-the-camera-and-photo-library-in-swiftui-0351a3c280f5 with some help from ChatGPT.

SuzGupta commented 5 months ago

From ChatGPT:

Camera Control Options with UIImagePickerController:

The UIImagePickerController offers a limited set of controls for customizing the camera interface and functionality. Here are some of the options you can configure:

sourceType: Determines whether the picker presents a photo library, a camera, or a saved photos album. cameraDevice: Allows you to choose between the front or rear camera. cameraFlashMode: Controls the camera's flash mode (on, off, or auto). showsCameraControls: Determines whether the default camera controls are visible. Setting this to false allows you to create a custom overlay. cameraOverlayView: Lets you add a custom overlay view on top of the default camera interface. videoQuality: Sets the quality of video capture. videoMaximumDuration: Sets the maximum duration for video capture.

For a custom camera interface with more control over the aspect ratio and other camera settings, you might consider using the AVFoundation framework. AVFoundation provides detailed control over the camera, including selecting input devices (camera), configuring output, handling capture sessions, and customizing the aspect ratio and resolution of the capture. Implementing a custom camera with AVFoundation requires more work but offers much greater flexibility and control over the camera functionality and interface within your app.

SuzGupta commented 5 months ago

Adding some more references...