縮放

2013-02-06 93 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]; 
矩陣