在Android的Surfaceview中缩放位图



我想在表面视图上慢慢调整位图的大小(比如放大位图)。当我为宽度和高度设置一些标准增加值时,它将显示更大的图像。正如我在onDraw方法

中给出的
can.drawBitmap(gball, lastVisitedX, lastVisitedY, paint);
                gball = getResizedBitmap(gball, bitmapInitHeight
                        + bitmapInitHeight, bitmapInitHeight + bitmapInitHeight);

public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
        int width = bm.getWidth();
        int height = bm.getHeight();
        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;
        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHeight);
        Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
                matrix, false);
        return resizedBitmap;
    }

但是当我尝试通过增加高度和宽度来调整大小时,比如

can.drawBitmap(gball, lastVisitedX, lastVisitedY, paint);
                gball = getResizedBitmap(gball, bitmapInitHeight
                        + zoomXValue, bitmapInitHeight + zoomYValue);
zoomXValue= zoomXValue+5;
zoomYValue= zoomYValue+5;

在onDraw方法中,但位图的大小调整与质量差。

最后我的问题是如何在不损害质量的情况下缩小比例。

你总是会有缩放问题,特别是如果你放大,你的图像上有相同的硬边,你可以避免这种情况的唯一方法(以某种方式)是使用更大的图像,总是缩小(仍然不会帮助硬边)。尝试将Filter设置为true,可能会有所帮助:)

最新更新