GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

Proper way to Handle Device Rotation using GPUImageStillCamera

Open powellmark opened this issue 14 years ago • 3 comments

Currently, I handle updating device rotation via:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    stillCamera.outputImageOrientation = toInterfaceOrientation;
}

This works well. However, initially, when switching to landscape the image was upside down. Therefore, I went into GPUImageVideoCamera and took a look at - (void)setOutputImageOrientation:(UIInterfaceOrientation)newValue. Switching the if ([self cameraPosition] == AVCaptureDevicePositionBack) to if ([self cameraPosition] == AVCaptureDevicePositionFront) line fixed the issue (landscape was now appearing oriented correctly). However, I have a strong feeling that something else is going on here, as someone would have noticed before now.

Is there another "proper" way to handle device rotation using GPUImageStillCamera?

powellmark avatar Jul 26 '12 14:07 powellmark

Does this happen with only the front camera or the back camera, or both? Philippe had provided a pull request a while ago that seemed to have fixed orientation issues for most people, which is where the above code came from. You're the first to say that this doesn't work.

In the SimpleVideoFilter example, I see that -didRotateFromInterfaceOrientation: is used instead of -willRotateToInterfaceOrientation:. If you try the approach from that example, does that help?

BradLarson avatar Jul 26 '12 15:07 BradLarson

It happens with both front and back cameras.

I did see SimpleVideoFilter example but the issue with that is it doesn't rotate the source until the rotation animation is complete, thus you get a "pop" after the fact. And I just ran the SimpleVideoFilter and I get the same upside down issue (with the pop) as well.

powellmark avatar Jul 26 '12 15:07 powellmark

Actually, ignore that last statement, the code from SimpleVideoFilter does work (I had forgotten to roll back my local changes to GPUImageVideoCamera.

It still pops, and I wonder why it doesn't work using willRotateToInterface? The same UIInterfaceOrientation is passed to the camera object.

powellmark avatar Jul 26 '12 18:07 powellmark