在 android 中旋转自定义视图

Rotate custom view in android

我正在尝试旋转图像。旋转效果很好,但是当我将旋转后的图像取回时,会出现一些空白 space。我应该怎么做才能删除那个空白space?

我试过这个代码:

public static Bitmap RotateBitmap(Bitmap source, float angle) {
        Matrix matrix = new Matrix();
        matrix.setRotate(90, 0, 0);
        matrix.postTranslate(source.getHeight(), 0);
        // matrix.postRotate(angle);
        return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
    }

Utility.tempBitmap = RotateBitmap(Utility.tempBitmap, -90);

我通过根据我的要求更改视图集位图中的一些更改来解决我的问题。使用此代码:

我之前用的代码(给我白space)

 public static Bitmap RotateBitmap(Bitmap source, float angle) {
    Matrix matrix = new Matrix();
    matrix.setRotate(90, 0, 0);
    matrix.postTranslate(source.getHeight(), 0);
    // matrix.postRotate(angle);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}

Utility.tempBitmap = RotateBitmap(Utility.tempBitmap, -90);

解决方案代码在这里:

public int setBitmap(final Bitmap bitmap) 
{
changeBitmapContrastBrightness(1, 50);
gapRect = new RectF();
dest = new Rect();
setBackgroundColor(Color.GRAY);
if (bitmap.getWidth() > bitmap.getHeight()) {
this.mbitmap = bitmap;
invalidate();
return 0;
}
this.mbitmap = bitmap;
 invalidate();
 return 1;