0

我正在制作一款基于 Pixel 的 Android 游戏。我有几个 8x8 的精灵需要调整大小以适应 100x100 的区域。作为测试是否可行,我尝试让图像填满整个画布。它有点工作,但它使 8x8 精灵变成了 12x12 精灵,使像素看起来非常奇怪和扭曲。这是我到目前为止所拥有的:

        Bitmap grass = BitmapFactory.decodeResource(getResources(), R.drawable.small);
        Paint configuration = new Paint();
        configuration.setDither(false);
        configuration.setAntiAlias(false);
        Matrix myMatrix = new Matrix();
        myMatrix.postScale(canvas.getWidth() / grass.getWidth(), canvas.getWidth() / grass.getHeight());
        Bitmap resizedBitmap = Bitmap.createBitmap(grass, 0, 0, grass.getWidth(), grass.getHeight(), myMatrix, false);
        canvas.drawBitmap(resizedBitmap, 0, 0, null);
4

1 回答 1

1

If you work on bitmaps then you simply can't. You'd minimize the distortion by scaling up by non-fractional factor so each pixed would be repeated same number of times (i.e. image 10x10 to 20x20 is scaled by factor of two, but 8x8 to 12x12 is 1,5 so no luck). The solution would be to have all assets in vector form (i.e. SVG) and then render them on run-time according to device density and other specs or prepare separate assets for various type of devices (which would blow application size up a bit)

于 2012-11-12T00:13:12.777 回答