-
Notifications
You must be signed in to change notification settings - Fork 408
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
Front facing camera always rotates the result #193
Comments
Hi, thanks for reporting this. |
Samsung galaxy s8, Google pixel. Both running on 7.0 |
Is the sample app affected too? |
In the sample app its flipping the image. But in my case its rotating as well as flipping. I am using the same code from your sample app. |
EDIT: Here is a video: I am also seeing this on my devices. I don't think it is specific to the front facing camera though, rather it is something I see occurring after resuming the app while in landscape mode.
Step # 3 can be replaced with any thing that switches or reinitializes the activity while in landscape mode. For instance, if you rotate to landscape, hit your recents button then return to the fotoapparat sample app and take a photo with the back facing camera the result will be rotated. I would guess this might be due to an issue with #90 assuming the default orientation is portrait at some point and not updating the orientation to landscape because no orientation update triggers it. Regarding #90 just in general, I do believe there are valid use cases for using system orientation instead of device orientation (which #90 reverses). For my use case I don't allow my camera activity into all 4 orientations (I think most camera apps prevent the upsidedown/reverse portrait orientation). For any application that doesn't allow all orientations, #90 complicates things. |
I think the issue in the video is different than the one in the reproduction steps. |
@Diolor Also having this issue on Galaxy Tab S2. Taking a front-facing photo with the device in landscape orientation is fine, but portrait orientation photos are rotated by 90 degrees clockwise. |
@Diolor Having the same issue with a BV6000s. How can this be addressed? |
@emilany The calculations inside |
I noticed that when I specify camera resolution parameter, like I want width:1080xheight:1440, but I have to set width=1440, height=1080, or I cannot get camera preview interface. Is this one of reason why it change orientation? |
For anyone curious, I was able to resolve the issue for my purposes by setting I use the following for rotating the image:
Where This seems to be working on front and back cameras and in all orientations on my devices including those with non-standard camera mountings like the Nexus 5x. |
I rotate bitmap and flip it while processing frames. override fun process(frame: Frame) {
Log.d(TAG, "frame: ${frame.image.size}, ${frame.size}")
YuvImage(
frame.image,
ImageFormat.NV21,
frame.size.width,
frame.size.height,
null
).let { yuvImage ->
ByteArrayOutputStream().use { output ->
yuvImage.compressToJpeg(
Rect(0, 0, frame.size.width, frame.size.height),
100,
output
)
output.toByteArray().apply {
BitmapFactory.decodeByteArray(this, 0, size)?.let { bitmap ->
process(
bitmap.rotate(90f).flip(
false, activeCamera == Camera.Front
)
)
bitmap.recycle()
}
}
}
}
}
private fun Bitmap.flip(horizontal: Boolean, vertical: Boolean): Bitmap {
val matrix = Matrix()
matrix.preScale((if (horizontal) -1 else 1).toFloat(), (if (vertical) -1 else 1).toFloat())
return Bitmap.createBitmap(this, 0, 0, width, height, matrix, true)
}
private fun Bitmap.rotate(degrees: Float): Bitmap {
val matrix = Matrix()
matrix.postRotate(degrees)
val scaledBitmap = Bitmap.createScaledBitmap(this, width, height, true)
return Bitmap.createBitmap(
scaledBitmap,
0,
0,
scaledBitmap.width,
scaledBitmap.height,
matrix,
true
)
}
|
I am using the latest version of your library. I am using only front facing camera. I took the code from your sample app. But when I take the picture from front facing camera, the result is rotated and zoomed. I have to rotate the result bitmap to 270 degree and then flip it to get the proper result. May I know the actual issue and How can it be fixed ? Here is my code:
The text was updated successfully, but these errors were encountered: