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

setScaleType() is useless #1

Open
zhanghq666 opened this issue Jun 19, 2016 · 1 comment
Open

setScaleType() is useless #1

zhanghq666 opened this issue Jun 19, 2016 · 1 comment

Comments

@zhanghq666
Copy link

I want to set my ImageViewTouch's scale type to CENTER_CROP by mPreviewIv.setScaleType(ImageView.ScaleType.CENTER_CROP), but it's useless. And, ImageViewTouchBase.DisplayType do not have similar enum value

@liangxiwei
Copy link

you should set it yourself like this.

int dwidth = imageInfo.getDrawable().getCurrent().getIntrinsicWidth(); int dheight = imageInfo.getDrawable().getCurrent().getIntrinsicHeight(); int vwidth = size.x; int vheight = size.y; float scale; float dx = 0, dy = 0; if (dwidth * vheight > vwidth * dheight) { scale = (float) vheight / (float) dheight; dx = (vwidth - dwidth * scale) * 0.5f; } else { scale = (float) vwidth / (float) dwidth; dy = (vheight - dheight * scale) * 0.5f; } Matrix matrix = new Matrix(); matrix.postScale(scale, scale); matrix.postTranslate(dx, dy); image.setImageDrawable(imageInfo.getDrawable().getCurrent(), matrix, 0.5f, scale * 8);

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

2 participants