Scale a BufferedImage the fastest and easiest way

前端 未结 6 565
春和景丽
春和景丽 2020-12-28 15:03

The task: I have some images, I scale them down, and join them to one image. But I have a little problem with the implementation:

The concr

6条回答
  •  再見小時候
    2020-12-28 15:36

    None of these answers were fast enough for me. So I finally programmed my own procedure.

    static BufferedImage scale(BufferedImage src, int w, int h)
    {
      BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
      int x, y;
      int ww = src.getWidth();
      int hh = src.getHeight();
      for (x = 0; x < w; x++) {
        for (y = 0; y < h; y++) {
          int col = src.getRGB(x * ww / w, y * hh / h);
          img.setRGB(x, y, col);
        }
      }
      return img;
    }
    

提交回复
热议问题