【问题标题】:how to rotate bitmap in android on center point using matrix如何使用矩阵在中心点旋转android中的位图
【发布时间】:2012-03-08 16:11:31
【问题描述】:

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

位图 bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.sticker01); int 宽度 = bitmapOrg.getWidth(); int height = bitmapOrg.getHeight();

矩阵矩阵 = 新矩阵(); matrix.postRotate(rotate, width/2, height/2);

位图 resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, 宽度,高度,矩阵,真); BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

imageView.setBackgroundColor(Color.WHITE); imageView.setImageDrawable(bmd); imageView.setScaleType(ScaleType.FIT_XY);

imageView --> 宽度和高度 = WRAP_CONTENT

旋转0度:

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

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

【问题讨论】:

  • 嗨,亲爱的,你知道吗

标签: android bitmap matrix android-imageview


【解决方案1】:

改变imageview scaleType:

imageView.setScaleType(ScaleType.CENTER);

【讨论】:

    【解决方案2】:

    使用中间值的矩阵后旋转

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-31
      • 1970-01-01
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      相关资源
      最近更新 更多