Java 如何将图像保存到RTF格式的文件?

Java 如何将图像保存到RTF格式的文件?,java,image,rtf,jtextpane,Java,Image,Rtf,Jtextpane,我有一个问题,我可以将文本保存到RTF文件,也可以将图像插入文件,但当我保存文件并再次加载时,图像不会显示。我曾尝试使用base64解决此问题,但没有成功。如何将图像保存到RTF文件中,并在重新打开文件时显示 这是我的代码: JFileChooser fileChooser = new JFileChooser(); int option = fileChooser.showOpenDialog(null); File file = fileChooser.getSelectedFile();

我有一个问题,我可以将文本保存到RTF文件,也可以将图像插入文件,但当我保存文件并再次加载时,图像不会显示。我曾尝试使用base64解决此问题,但没有成功。如何将图像保存到RTF文件中,并在重新打开文件时显示

这是我的代码:

JFileChooser fileChooser = new JFileChooser();
int option = fileChooser.showOpenDialog(null);
File file = fileChooser.getSelectedFile();

if (option == JFileChooser.APPROVE_OPTION) {
    try {
        BufferedImage image = ImageIO.read(file);
        image = Scalr.resize(image, 200);
        document = (StyledDocument) textPane.getDocument();
        javax.swing.text.Style style = document.addStyle("StyleName",
                null);
        StyleConstants.setIcon(style, new ImageIcon(image));
        document.insertString(document.getLength(), "ignored text",
                style);
    }
    catch (Exception ex) {
        ex.printStackTrace();
    }
}

if (option == JFileChooser.CANCEL_OPTION) {
    fileChooser.setVisible(false);
}
尝试替代默认选项

尝试替代默认选项