gpt4 book ai didi

java - 在java中输出图像

转载 作者:行者123 更新时间:2023-12-02 03:46:33 24 4
gpt4 key购买 nike

我用java编写了一个程序,它接受彩色图像并将其转换为灰度图像。该图像被读取为 BufferedImage,提取并修改 RGB 分量,并将其设置为同一图像以显示在创建的控制台窗口上。但我希望输出为单独的 jpeg 或 png 文件。有人可以告诉我该怎么做吗?

编辑:

    public static void saveToFile(BufferedImage img)throws FileNotFoundException, IOException
{
File outputfile = new File("E:\\Java\\Sample.jpg");
ImageIO.write(img, "jpg", outputfile);
}

这是我希望使用的方法。这里 img 是我正在使用的图像(编辑,即更改像素值)。我想要存储输出的路径是 E:\Java 。请有人帮忙..

最佳答案

使用这种方式:

{
File outputfile = new File("E:\\Java\\Sample.jpg");
FileOutputStream fos = new FileOutputStream(outputfile);
ImageIO.write(img, "jpg", outputfile);
fos.flush();
fos.close()
}

关于java - 在java中输出图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36248009/

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