gpt4 book ai didi

java - 如何使用 im4java 调整缓冲图像的大小并将输出作为 bufferedImage?

转载 作者:行者123 更新时间:2023-11-29 03:04:30 26 4
gpt4 key购买 nike

当我尝试调整图像大小时,出现异常“java.lang.IllegalStateException:给定格式没有 ImageReader”。

 public static void main(String... args) throws Exception {   
IMOperation op = new IMOperation();
op.addImage();
op.resize(350)
op.addImage()
BufferedImage images = ImageIO.read(new File("image.jpg"));

// set up command
ConvertCmd convert = new ConvertCmd();
Stream2BufferedImage s2b = new Stream2BufferedImage();
convert.setOutputConsumer(s2b);

// run command and extract BufferedImage from OutputConsumer
convert.run(op,images);
BufferedImage img = s2b.getImage();
}

最佳答案

伙计们,我已经解决了这个问题。实际上我必须指定输出图像的图像类型

public static void main(String... args) throws Exception {   
IMOperation op = new IMOperation();
op.addImage();
op.resize(350)
op.addImage("jpg:-")
BufferedImage images = ImageIO.read(new File("image.jpg"));

// set up command
ConvertCmd convert = new ConvertCmd();
Stream2BufferedImage s2b = new Stream2BufferedImage();
convert.setOutputConsumer(s2b);

// run command and extract BufferedImage from OutputConsumer
convert.run(op,images);
BufferedImage img = s2b.getImage();
}

关于java - 如何使用 im4java 调整缓冲图像的大小并将输出作为 bufferedImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32739699/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com