テキストを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);
}