2013-01-15 30 views
0
OverlayObject overlayObject = overlayObjects.get(index); 
Bitmap dotIndicator = overlayObject.DTO.dotIndicatorBitmap; 

int width = dotIndicator.getWidth(); 
int height = dotIndicator.getHeight(); 

Log.d("dotIndicator.getWidth()", "" + width); 
Log.d("dotIndicator.getHeight()", "" + height); 

Matrix matrix = new Matrix(); 
matrix.postRotate(gbConstants.dotIndicatorRotationFactor, width/2, height/2); 

Bitmap newBitmap = Bitmap.createBitmap(dotIndicator, 0, 0, 
    width, width, matrix, true); 

Log.d("newBitmap.getWidth()", "" + newBitmap.getWidth()); 
Log.d("newBitmap.getHeight()", "" + newBitmap.getHeight()); 

日誌的結果:)d/dotIndicator.getWidth((20739):: 01-15 14:46:16.485 102 01-15 14:46:16.485:D/newBitmap.getWidth()(20739):104 01-15 14:46:16.485:D/dotIndicator.getHeight()(20739):102 01: d/newBitmap.getHeight()(20739):104機器人Matrix.postRotate()方法使圖像尺寸大

01-15 14:46:16.555: D/dotIndicator.getWidth()(20739): 104 
01-15 14:46:16.555: D/dotIndicator.getHeight()(20739): 104 
01-15 14:46:16.555: D/newBitmap.getWidth()(20739): 106 
01-15 14:46:16.555: D/newBitmap.getHeight()(20739): 106 

**注:gbConstants.dotIndicatorRotationFactor = 1(I將其設置爲這個號碼,以用於調試的最低值)

每創建一次newBitmap,圖像每旋轉1度,就會在寬度和高度上添加2個像素。我瀏覽過其他鏈接和問題,但迄今爲止還沒有人回答我的問題。我也一遍又一遍地嘗試調試,以確保沒有其他方法引用會影響結果的變量和對象。提前致謝!

回答

0

答案很簡單。 旋轉1°的圖像需要更多的寬度和高度空間,所以結果是完全正確的。因爲否則圖片的角落將被切斷。

拿一張紙並旋轉它,你會看到寬度和高度將如何增加,直到你達到45°。

編輯:也許這可以幫助你:Image changes size as it's rotated. How do I stop this?

+0

感謝您的回答。我會試試看。這實際上是我的第一個理論,但直到現在我還沒有證實。 – chjarder

+0

這是很久以前的事了,今天我也遇到了同樣的問題。我不得不導致使用形狀和ImageViews而不是手動位圖旋轉 - 非常方便,耗時更少。不管怎麼說,多謝拉。 – chjarder

0

這是因爲,如果你是通過一個角度旋轉圖像,得到的圖像將讓您的傾斜圖像的 方之一。 如下圖所示。

enter image description here