如何使用矩阵在中心点上旋转android中的位图
我使用矩阵来旋转我的图像,它可以工作,但我对新图像位图有一些问题。 即使我设置了枢轴,新位图仍有一些空间。我应该做什么来旋转图像,但我不想要空间。我使用下面的代码来旋转位图:
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.sticker01); int 宽度 = bitmapOrg.getWidth(); int height = bitmapOrg.getHeight();
矩阵矩阵 = new Matrix(); 矩阵.postRotate(旋转,宽度/2,高度/2);
位图调整大小Bitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, 宽度、高度、矩阵、true); BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
imageView.setBackgroundColor(Color.WHITE); imageView.setImageDrawable(bmd); imageView.setScaleType(ScaleType.FIT_XY);
图像视图 -->宽度和高度 = WRAP_CONTENT
旋转 0 度:
旋转 10 度: 它在真实图像周围有空间。
旋转 50 度: 它在真实图像周围有空间(甚至更大的空间)。
I use matrix to rotate my image, it's working but i have some problem with new image bitmap.
The new bitmap have some space even though I have set the pivot. What should i do to rotate the image but i don't want the space. I use this code below to rotate the bitmap:
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 --> width & height = WRAP_CONTENT
Rotate 0 degree:
Rotate 10 degree:
It has space around the real image..
Rotate 50 degree:
It has space around the real image (even bigger space)..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
改变imageview的scaleType:
Change the imageview scaleType:
使用带有中值的矩阵后旋转
matrix.postScale(scale,scale,mid.x,mid.y);
Use matrix post rotate with mid value
matrix.postScale(scale, scale, mid.x, mid.y);