2013-01-15 29 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