how do I scale a BufferedImage

前端 未结 3 1225
南笙
南笙 2021-01-12 12:05

I have viewed this question, but it does not seem to actually answer the question that I have. I have a, image file, that may be any resolution. I need to load that image

3条回答
  •  情深已故
    2021-01-12 12:10

    You can create a new BufferedImage of the size you want and then perform a scaled paint of the original image into the new one:

    BufferedImage resizedImage = new BufferedImage(new_width, new_height, BufferedImage.TYPE_INT_ARGB); 
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(image, 0, 0, new_width, new_height, null);
    g.dispose();
    

提交回复
热议问题