Skip to content
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

CENTER_CROP #10

Open
DylanMay opened this issue May 28, 2015 · 3 comments
Open

CENTER_CROP #10

DylanMay opened this issue May 28, 2015 · 3 comments

Comments

@DylanMay
Copy link

the scaleType "CENTER_CROP" is not totally same with the CENTER_CROP of ImageView

@xiliangxiaoke
Copy link

yes,I also find this problem. is a litter bigger .

@ObidosDev
Copy link

ObidosDev commented Sep 21, 2016

Hi!)
I also find this problem. I tried to resolve this problem.))
Problem: when you setup the video for playing, it will be scaled to view sizes, than you try to apply the matrix. 1) You must scale back the video to initial sizes and only then apply the new scale.
This is my code only for CENTER_CROP, it have to be the same with the CENTER_CROP of ImageView:

private void updateTextureViewSize() {
        float viewWidth = getWidth();
        float viewHeight = getHeight();

        float scaleX = mVideoWidth/viewWidth;
        float scaleY = mVideoHeight/viewHeight;

        int pivotPointX;
        int pivotPointY;
        pivotPointX = (int) (viewWidth / 2);
        pivotPointY = (int) (viewHeight / 2);

        Matrix matrix = new Matrix();
        //scale video back to its size
        matrix.preScale(scaleX, scaleY, pivotPointX, pivotPointY);

        //scale video for CENTER_CROP
        scaleX = viewWidth / mVideoWidth;
        scaleY = viewHeight / mVideoHeight;
        float scale = Math.max(scaleX, scaleY);
        matrix.postScale(scale, scale, pivotPointX, pivotPointY);
        setTransform(matrix);
    }

@Inoinho
Copy link

Inoinho commented Apr 24, 2018

matrix.setScale(scaleX/2, scaleY/2, pivotPointX, pivotPointY);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants