gpt4 book ai didi

java - 使用压缩的缓冲图像转换

转载 作者:行者123 更新时间:2023-12-02 07:17:17 25 4
gpt4 key购买 nike

尝试读取缓冲的 bmp 图像,然后压缩转换为 jpeg。缓冲图像行有问题。谢谢,非常感谢您的帮助。

public void jpegconvert(String Fname, String Crate)
{

BufferedImage image = ImageIO.read(Fname);

Iterator<ImageWriter> i = ImageIO.getImageWritersByFormatName("jpeg");

// Just get the first JPEG writer available
ImageWriter jpegWriter = i.next();

// Set the compression quality to 0.8
ImageWriteParam param = jpegWriter.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(0.8f);

// Write the image to a file
FileImageOutputStream out = new FileImageOutputStream(new File("newimage.jpg"));
jpegWriter.setOutput(out);
jpegWriter.write(null, new IIOImage(image, null, null), param);
jpegWriter.dispose();
out.close();
}
}

悬停错误表示:

no suitable method found for read(String)
method ImageIO.read(ImageInputStream) is not applicable
(actual argument String cannot be converted to ImageInputStream by method invocation conversion)
method ImageIO.read(URL) is not applicable
(actual argument String cannot be converted to URL by method invocation conversion)
method ImageIO.read(InputStream) is not applicable
(actual argument String cannot be converted to InputStream by method invocation conversion)
method ImageIO.read(File) is not applicable
(actual argument String cannot be converted to File by method invocation conversion)

最佳答案

问题出在这个特定的代码上:
ImageIO.read(Fname);
因为 Fname 是一个 String 并检查 API for read method它在任何重载方法中都不采用 String 作为参数

这个reference可能对你有帮助

关于java - 使用压缩的缓冲图像转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14789893/

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