休息 Web 服务下载图像并根据需要在 linux 系统上调整大小

Rest Web Service to download image & resize it if needed on linux system

我的任务是创建网络服务来下载图像,如果需要,根据需要的高度和宽度调整它的大小作为可选参数,对于本地系统,即 windows,代码工作正常,但是服务器,即linux,显示空指针异常,以下是我的代码

 public File resizeImage(File file,String filePath,int width,int height) throws Exception {
        Graphics2D g = null;
        File file2 = File.createTempFile(file.getName(), FilenameUtils.getExtension(filePath));
        try{
            BufferedImage img = ImageIO.read(file);
            int w = img.getWidth();  
            int h = img.getHeight();  
            BufferedImage dimg = new BufferedImage(width, height, img.getType());  
            g = dimg.createGraphics();  
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);  
            g.drawImage(img, 0, 0, width, height, 0, 0, w, h, null);
            ImageIO.write(dimg, FilenameUtils.getExtension(filePath), file2);
        } finally {
            g.dispose();  
        }
        return file2;
    }

请帮助我,

提前致谢

好吧,查询参数确实是可选的,只需检查它们是否为空,如果不是,则调整大小。