1. 使用EpsGraphics2D的jar包实现
2. 代码如下:
import org.sourceforge.jlibeps.epsgraphics.EpsGraphics2D;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.UUID;
public class Main {
public static void main(String[] args) {
BufferedImage image = null;
try {
image = ImageIO.read(new File("C:\\Users\\13180\\Downloads\\rest.png"));
} catch (IOException e) {
e.printStackTrace();
}
EpsGraphics2D graphics2d = new EpsGraphics2D();
try {
graphics2d.drawImage(image, -1, -1, null);
} catch (Exception e1) {
e1.printStackTrace();
}
String path = "C:\\Users\\13180\\Downloads\\" + UUID.randomUUID() + ".eps";
try {
FileWriter fos = new FileWriter(path);
fos.write(graphics2d.toString());
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
jar包下载:https://download.csdn.net/download/zhaokai621/87484852
jar包放入lib文件夹,右键add as library