matrix - Android ImageView scale image and center -


i need scale image inside imageview, need use matrix doing so,

so do;

private void scaleimage(float scalefactor, float focusx,float focusy) {     matrix displaymatrix= new matrix();     matrix.postscale(scalefactor, scalefactor);     displaymatrix.set(matrix);     imageview.setimagematrix(displaymatrix); } 

the problem no matter not able center image inside imageview,

i need put image @ center (leaving white margins if image smaller view)

i have been bangin head hours, please help.


i have looked extensively @ https://stackoverflow.com/a/6172226/1815311, without success.

all have find new x , y coordinates place image , translate matrix, image moves center of imageview. entire scaleimage method can this:

private void scaleimage(float scalefactor, float focusx, float focusy) {     matrix displaymatrix = new matrix();     matrix matrix = imageview.getimagematrix();      float x = (imageview.getwidth() - imageview.getdrawable().getintrinsicwidth() * scalefactor) / 2;     float y = (imageview.getheight() - imageview.getdrawable().getintrinsicheight() * scalefactor) / 2;      matrix.postscale(scalefactor, scalefactor);     matrix.posttranslate(x, y);      displaymatrix.set(matrix);     imageview.setimagematrix(displaymatrix); } 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -