android – Upside down camera preview byte array-ThrowExceptions

Exception or error:

I have a camera application which is locked to landscape. When needed I rotate the raw bytes gotten from on onPreviewFrame() and use them to encode a video.

This approach however fails in the Nexus 5X and 6 devices, because their reversed sensor gives me upside-down frames.

As rotating the preview won’t help me in this case, as described here:

This does not affect the order of byte array passed in
onPreviewFrame(byte[], Camera)

I’d like to know if there’s any way to detect that the camera sensor is reversed and/or the raw frame is upside down, so an extra correction is added when rotating them.

How to solve:

the camera sensor of the Nexus 5x and 6 are rotated 180 degrees. A lot of apps had this problem when the device was released. You should take this into account while creating a camera app and set your surface rotation accordingly.

For more information go to

Leave a Reply

Your email address will not be published. Required fields are marked *