【问题标题】:How to edit the format of Image in Java?如何在 Java 中编辑图像的格式?
【发布时间】:2018-12-04 11:36:29
【问题描述】:

我有一个上传图片的表单,所以我想要的是,每当用户上传任何类型的图片(png/jpg 等)时,将该图片转换为 jpg 并将该图片保存到 Multipart 的存储中。

【问题讨论】:

标签: java image format


【解决方案1】:

我认为您可以对上一个问题做出回应:

Image conversion in JAVA

File inputFile = new File("/fileOfYourForm.png");
File outputFile = new File("NewImage.jpg");
try (InputStream is = new FileInputStream(inputFile)) {
    BufferedImage image = ImageIO.read(is);
    try (OutputStream os = new FileOutputStream(outputFile)) {
        ImageIO.write(image, "jpg", os);
    } catch (Exception exp) {
        exp.printStackTrace();
    }
} catch (Exception exp) {
    exp.printStackTrace();
}

【讨论】:

    猜你喜欢
    • 2018-05-31
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 2018-02-19
    • 1970-01-01
    • 2011-11-28
    • 1970-01-01
    相关资源
    最近更新 更多