使用旋转矩阵位图位图、旋转矩阵

2023-09-05 10:37:18 作者:劫数

在使用矩阵旋转位图,顶点是不稳定的。

 矩阵矩阵=新的Matrix();
    matrix.postRotate(mDegree,100,100);
    mCompasstemp = Bitmap.createBitmap(mCompPic,0,0,mCompPic.getWidth(),mCompPic.getHeight(),矩阵,真);
    mCompassHud.setImageBitmap(mCompasstemp);
 

我的code输出像 -bitmap会旋转。 我的位图-vertex并不稳定。 -bitmap是调整

我需要禁用图像缩放,使旋转stable.Can请你提出了一个解决方案?

解决方案

而不是直接从原来的创建新的位图,另一个(更直接的,恕我直言)选择是创建所产生的位图,创建一个画布位图,然后做你的旋转/平移/缩放画布上绘制原来的位图到通过画布的新位图。

基本上,你正在寻找,然后在:

  scaledImage = Bitmap.createBitmap(croppedWidth,croppedHeight,Bitmap.Config.ARGB_8888);

  帆布offscreenCanvas =新的Canvas(scaledImage);
  字模=新的Matrix();
  matrix.setRotate(旋转,CENTREX,centreY);
  matrix.postScale(将scaleX,的scaleY);
  offscreenCanvas.setMatrix(矩阵);

  offscreenCanvas.drawBitmap(pickedImage,0,0,新涂料(Paint.DITHER_FLAG));
 

旋转矩阵

While rotating a bitmap using matrix, vertex is not stable..

  Matrix matrix = new Matrix();
    matrix.postRotate(mDegree,100,100);
    mCompasstemp = Bitmap.createBitmap(mCompPic, 0, 0, mCompPic.getWidth(), mCompPic.getHeight(), matrix, true);
    mCompassHud.setImageBitmap(mCompasstemp);

Output of my code is like -bitmap will rotate. -vertex of my bitmap is not stable. -Bitmap is resizing

I need disable image resizing and make the rotation stable.Can you please suggest a solution for this?

解决方案

Rather than creating your new Bitmap directly from the original, another (more straight-forward, imho) option is to create the resultant Bitmap, create a Canvas with that Bitmap, then do your rotation/translation/scaling on the Canvas and draw the original Bitmap onto the new Bitmap via the Canvas.

Basically, you're looking, then, at:

  scaledImage = Bitmap.createBitmap (croppedWidth, croppedHeight, Bitmap.Config.ARGB_8888);

  Canvas offscreenCanvas = new Canvas (scaledImage);
  Matrix matrix = new Matrix();
  matrix.setRotate (rotations, centreX, centreY);
  matrix.postScale(scaleX, scaleY);
  offscreenCanvas.setMatrix (matrix);

  offscreenCanvas.drawBitmap (pickedImage, 0, 0, new Paint(Paint.DITHER_FLAG));