Android,围绕自我中心旋转位图而不缩放它

问题描述 投票:0回答:1

当我围绕它旋转位图时,位图图像的大小发生了变化,旋转显示出来。

public static Bitmap RotateBitmap(Bitmap source, int width, float angle) {
        Matrix matrix = new Matrix();
        int px = width / 2;
        matrix.postRotate(angle, px, px);
        Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, width, width, matrix, true);
        return bitmap;
    }

每次调用在画布上绘制它时,一些添加到位图的宽度和高度并随着摇动旋转。如何平滑旋转而不抖动位图?

android canvas bitmap android-canvas android-bitmap
1个回答
0
投票

它正在调整大小,因为你传递了它的一半宽度。用这个:

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

至于摇动,你必须在另一个线程上调用它。 (AsyncTask等)

© www.soinside.com 2019 - 2024. All rights reserved.