Java Image 类转换为 File 文件 - 代码示例
要将 Java Image 类转为 File,可以使用 ImageIO 类中的 write 方法。以下是示例代码:
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ImageToFile {
public static void main(String[] args) throws IOException {
BufferedImage image = ImageIO.read(new File('input.jpg')); // 读取图像文件
File output = new File('output.jpg'); // 创建输出文件
ImageIO.write(image, 'jpg', output); // 将图像写入输出文件
}
}
这将从文件'input.jpg'中读取图像,将其写入名为'output.jpg'的文件中。您可以根据需要更改输入和输出文件的名称和路径。
原文地址: https://www.cveoy.top/t/topic/oYro 著作权归作者所有。请勿转载和采集!