【问题标题】:Is there a way to scale an image down to a specific size?有没有办法将图像缩小到特定尺寸?
【发布时间】:2017-04-30 11:53:45
【问题描述】:

我目前正在尝试运行某种 2D 地牢爬行者(想想:roguelike)。现在我想使用方形瓷砖(32x32),但我想知道是否有办法让我的纹理具有更高的分辨率,比如 64x64,然后将它们缩小到 32x32 的正方形上?

我想肯定有,因为几乎所有游戏都以一种或另一种方式做到这一点,但我在网上能找到的似乎都是关于 3D 的东西。

【问题讨论】:

  • 有可能,有几种方法可用。不过,不知道任何图书馆。而且相当多的游戏只提供多种分辨率的文件(一个游戏的安装大小超过 100Gb,因为它们提供了高达 4k 或 8k 的纹理文件,我不记得是哪个)。
  • “有办法吗?”是的。

标签: java textures scaling texture2d


【解决方案1】:

是的。绘制图像时,可以添加新的宽度和高度以调整其大小。

public static BufferedImage resizeImage(BufferedImage image, int newwidth, int newheight) {
    BufferedImage image2 = new BufferedImage(newwidth, newheight, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image2.getGraphics();
    g.drawImage(image, 0, 0, newwidth, newheight, null);
    g.dispose();
    return image2;
}

请参阅here 了解更多信息。

【讨论】:

    猜你喜欢
    • 2014-07-16
    • 1970-01-01
    • 1970-01-01
    • 2011-03-28
    • 2011-04-03
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多