2013-03-12 66 views
1

我有一个问题,因为我能够将文本保存到RTF文件,并且能够将图像插入到该文件中,但是当我保存该文件并再次加载时,图像不显示。我曾尝试使用base64来解决这个问题,但那并不奏效。我能做些什么来将图像保存到RTF文件中,并在文件重新打开时显示它?如何将图像保存为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); 
} 

回答