简体   繁体   中英

Camera flip animation Using TextureView

I am using TextureView to show my live stream from the camera. I wrote a function that switch between front and back camera through flip animation. When I flip The Textureview through animation from 90 to 180 degree. It show the live stream right to left instead of left to right. This behavior is understandable because left corner become right on flip animation. How can I change the live stream after animation. I have tried a lot but could not find any solution. Any Suggestion or solution to solve this problem please.

You can apply a transformation matrix on your texture view to flip your camera horizontally.

You need to apply this transformation in onSurfaceTextureAvailable(..) callback:

public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) 
{
//If you are in portrait mode.
//mCamera.setDisplayOrientation(90);

//If you want to flip only front camera.
if(YOUR_FRONT_CAMERA_FLAG)
{
    Matrix matrix = new Matrix();
    matrix.setScale(-1, 1);
    matrix.postTranslate(width, 0);
    mTextureView.setTransform(matrix);
}
}

I hope this solves your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM