我使用矩阵来旋转我的图像,虽然它能工作,但是新的位图有一些空白区域。即使我已经设置了中心点,我应该怎么做才能旋转图像但不想要这些空白区域呢?我使用下面的代码来旋转位图:
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.sticker01); int width = bitmapOrg.getWidth(); int height = bitmapOrg.getHeight();
Matrix matrix = new Matrix(); matrix.postRotate(rotate, width/2, height/2);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
imageView.setBackgroundColor(Color.WHITE); imageView.setImageDrawable(bmd); imageView.setScaleType(ScaleType.FIT_XY);
imageView --> 宽度和高度 = WRAP_CONTENT
旋转0度:
旋转10度: 真实图像周围有空白区域。
旋转50度: 真实图像周围有空白区域(甚至更大的空白区域)。