Resizing an image in swing

前端 未结 4 1237
名媛妹妹
名媛妹妹 2021-01-06 02:46

I have snippet of code that I am using for the purpose of resizing an image to a curtain size (I want to change the resolution to something like 200 dpi). Basically the reas

4条回答
  •  暖寄归人
    2021-01-06 02:53

    Here is my solution:

        private BufferedImage resizeImage(BufferedImage originalImage, int width, int height, int type) throws IOException {  
            BufferedImage resizedImage = new BufferedImage(width, height, type);  
            Graphics2D g = resizedImage.createGraphics();  
            g.drawImage(originalImage, 0, 0, width, height, null);  
            g.dispose();  
            return resizedImage;  
        }  
    

提交回复
热议问题