I am going through a lot of answers, but there is a code that I do not know in which direction to choose. I hope someone can point me in the right direction.
I have a custom camera app where I show the preview ( SurfaceHolder
) from the front or back camera. I have a button where the user can rotate the preview image for 90/180/270 degrees. This value is saved and applied to the camera and the preview image.
Although the orientation of the images the users take, the picture is not the same. My question is how do I account for user and device orientation so that the output image can be rotated just like the preview image?
A possible direction (if you are on Android studio) by dragging the code, step by step and its The requirements will be to modify. It certainly does not 'do whatever your app' does, but it can get you off-the-ground (or you can get even more confused). And look, IT handles only rear CAM anyway, a small front of information.
1 / When your activity begins (on cret), record your rotation and lock it so that you do not see the view at any time while transferring your phone. Depending on your initial position, your orientation port or land may be. You can also 'force it' for LAND, for example, but when your activity begins, it will look jerky.
2 / onSurfaceChanged gives you the size of your surface. It can be PART (WLT; H) or Land (W> H) You can send the camera manager W, H to your camera manager to choose the ideal preview size. Since 'getSupportedPreviewSizes' most types (I would always like to say, but not 100% fixed) according to type of land (W> H), you swap your surface W and H.
3 / don does not forget about 'set display ormentation' in your initial orientation, so your preview is not sideways.
4 / Approximately, your surface W is not equal to one of the proposed preview sizes: h, resulting in crushed / enhanced preview (just look at any object with you Cam preview). So now you have to adjust the flat shape again, look at the 'set layout side' at the end of the 'size of the surface'. It is worth noting that you can either adjust the surface for a fit-in (letterbox), as a result the sides may have two background colored bandages, or fill (pan and scan) to fill your entire surface. Some of your screens (which cares)
This helps you correct the preview. I should also mention that there is another quote with preview orientation. Some tablets (Nexus 1 genes, ...) have natural orientation land, but some (such as Samsung 8 3.0) have a port in it. This problem is adjusted during the initial time and expresses itself in the 'isLandTab' boolean.
5 / Now, when you finally get your picture from camera.gate, then you move it back using the same amount. You revolve your preview rather expensive operation (memory-wise). You have to do it in the bitmap, rotate and ... whatever you want to do. Again, shrink, show, ....
Now, when you finally meet through this nonsensical rant, you can ask yourself. Is it not better that you launch activity in the land, lock it in this case?
- To swap it does not want W, H
- Display Orientation Set Do not
- Do not want to rotate the image after receiving the image.
You need to adjust the surface size of the shape to fit in proportion to the proposed / selected preview, as well as to dance.
Have fun, good luck
No comments:
Post a Comment