Android: Using setTransform for flipping the live TextureView

Viewed 9982

MainActivity

public class MainActivity  extends Activity implements TextureView.SurfaceTextureListener{
    private Camera mCamera;
    private TextureView mTextureView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTextureView = new TextureView(this);
        mTextureView.setSurfaceTextureListener(this);

        setContentView(mTextureView);
    }

    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) 
    {
        mCamera = Camera.open(0);

        try {
            mCamera.setPreviewTexture(surface);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mCamera.startPreview();
    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture arg0) {
        mCamera.stopPreview();
        mCamera.release();
        return true;
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture arg0, int arg1,
            int arg2) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture arg0) {
        // TODO Auto-generated method stub
    }
}

The live preview is flipped to left side. On searching I found that setTransform is a solution, but I am not sure how to use it. Can anyone give me a code example?

NB: It is to flip the live preview not an image.

1 Answers
Related