缩放

2013-02-06 59 views
1

这里是我的问题后获得绘制显示尺寸:
怎样才能在scalling后像素的ImageView的内部绘制的显示尺寸,假设ImageView的大小不等于缩放绘制?缩放

很多方法只是返回Drawable的原始大小或者只是ImageView的大小。

这里是一个图片说明什么,我想:

http://image.noelshack.com/fichiers/2013/06/1360144144-sans-titre.png

1 - > ImageView的大小
2 - >我想在PX得到缩放后的图像尺寸

谢谢您。

回答

2

从您发布的图片我假设你对你的ImageView

这样你就可以计算显示大小,像这样

boolean landscape = imageView.getWidth() > imageView.getHeight(); 

    float displayedHeight; 
    float displayedWidth; 

    if (landscape){ 
     displayedHeight = imageView.getHeight(); 
     displayedWidth = (float) drawableWidth * imageView.getHeight()/drawableHeight; 
    } else { 
     displayedHeight = (float) drawableHeight * imageView.getWidth()/drawableWidth; 
     displayedWidth = imageView.getWidth(); 
    } 

注有FIT_CENTER的scaleType(或CENTER_INSIDE与绘制比ImageView的大):代码为了可读性而不简化。

可应用于所有scaleTypes另一种更鲁棒的方法是使用其的ImageView用于缩放图像

float[] f = new float[9]; 
imageView.getImageMatrix().getValues(f); 
float displayedWidth = drawableWidth * f[Matrix.MSCALE_X]; 
float displayedHeight = drawableHeight * f[Matrix.MSCALE_Y]; 
矩阵