首页 文章

如何使用矩阵在android中心点旋转位图

提问于
浏览
4

我使用矩阵来旋转我的图像,它正在工作但我对新图像位图有一些问题 . 即使我设置了枢轴,新的位图也有一些空间 . 我该怎么做才能旋转图像,但我不想要空间 . 我使用下面的代码来旋转位图:

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);

位图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 - > width&height = WRAP_CONTENT

旋转0度:
enter image description here

旋转10度:
enter image description here
它在真实图像周围有空间..

旋转50度:
enter image description here
它在真实图像周围有空间(甚至更大的空间)..

2 回答

  • 0

    使用矩阵后旋转中间值

    matrix.postScale(scale,scale,mid.x,mid.y);

  • 0

    更改imageview scaleType:

    imageView.setScaleType(ScaleType.CENTER);
    

相关问题