Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App is zoomed in after zooming in while taking picture (AR Kit) iOS only. #82

Open
marcolbx opened this issue Jan 25, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@marcolbx
Copy link

marcolbx commented Jan 25, 2022

Description of the bug
Only happening on iOS!
We are currently using this asset to take pictures and we are also using AR Core/Kit. If we are taking a picture and we zoom in, then after exiting the native camera, the zoom is still there and we cannot reset it because AR Core/Kit takes control of the camera stream.

Reproduction steps
Start the plugin to take a picture.
Zoom in,
Take picture or close the native camera,
The camera is zommed in the entire app.

Additional info
On Android the camera's zoom is reset automatically, which could probably mean that it could be also done for iOS.

@marcolbx marcolbx added the bug Something isn't working label Jan 25, 2022
@yasirkula
Copy link
Owner

That is indeed a very interesting issue. I don't create the camera user interface manually (i.e. zoom button, switch camera button, capture button), they are all parts of the native camera user interface (a preset). This native preset returns me only a single value: the captured photo's path. It doesn't return the zoom level or AFAIK allow me to change the zoom level programmatically. So, at the moment, this issue will probably remain open.

@marcolbx
Copy link
Author

let me know if you need more details in the future, we will certainly keep trying to find a solution

@yasirkula
Copy link
Owner

yasirkula commented Jan 25, 2022

Can you try adding the following code to here and cross your fingers: [[AVCaptureDevice defaultDeviceWithDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionBack] videoZoomFactor] = 1.0;

NOTE: I didn't compile this code myself, there might be compiler errors.

PPS. You can add this code in the Xcode project (while testing), no need to rebuild the Unity project.

@marcolbx
Copy link
Author

marcolbx commented Jan 27, 2022

So I do not have Xcode with me, but I changed the .mm file by adding your line of code on line 276, and tried with Unity Cloud builds and I have this:

Error from Cloud Build: /BUILD_PATH/xxxxxxx/temp20220127-4912-acmz1m/Libraries/Plugins/NativeCamera/iOS/NativeCamera.mm:277:171: assigning to 'readonly' return result of an Objective-C message not allowed

I believe it is on: videoZoomFactor = 1.0, could it be that we cannot set it? I wonder also if there is some other zoomFactor property since this one is for video but the problem is for taking pictures 🤔
PS: I do not know Objective C++ so I do not know if your recommendation works.

@marcolbx marcolbx changed the title App is zoomed in after zooming in while taking picture (AR Kit/Core) iOS only. App is zoomed in after zooming in while taking picture (AR Kit) iOS only. Jan 27, 2022
@yasirkula
Copy link
Owner

yasirkula commented Jan 27, 2022

How about this:

[AVCaptureDevice defaultDeviceWithDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionBack].videoZoomFactor = 1.0;

PS. There is no equivalent of AVMediaTypeVideo for photos, so I'm hoping that it points to the camera that takes the photos.

@marcolbx
Copy link
Author

I could create the build and test, however it was not successful. The problem persists

@yasirkula
Copy link
Owner

My final attempt:

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionBack];
if (device != nil)
{
	NSError *error = nil;
	if ([device lockForConfiguration:&error])
	{
		device.videoZoomFactor = 1.0;
		[device unlockForConfiguration];
	}
	else
	{
		NSLog(@"Reset zoom error: %@", error);
	}
}

As an unrelated note, if you can take pictures by capturing a screenshot of the AR camera instead (same solution I've proposed in #84), then you won't have zoom issues, as well.

@marcolbx
Copy link
Author

Same result, it is still a problem. Yes, the screenshot would solve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants