0

私は画像編集アプリを開発しているので、で選択した画像を表示したいJFileChooserので、すべての形式を表示できるようにするための最良の方法は何jpgですか?などはpng、filechooser の呼び出しに使用されます。gifOpenButton

private void OpenActionPerformed(java.awt.event.ActionEvent evt) {
       int returnVal = fileChosser.showOpenDialog(this);
       if (returnVal == JFileChooser.APPROVE_OPTION) {
           File file = fileChosser.getSelectedFile();
           // What to do with the file
           // I want code for this part
           try {
             //code that might create an exception 
           } 
           catch (Exception e1) {
             e.printStackTrace();
           }
       }
}
4

1 に答える 1

1

おそらく最も簡単な方法は、ファイルの URL (またはバイトとしてのファイルの内容、またはファイル名) から ImageIcon を作成し、この ImageIcon を JLabel にラップすることです。

iconLabel.setIcon(new ImageIcon(file.toURI().toURL()));

ただし、アプリで画像を編集するjava.awt.Image場合は、インスタンスの操作方法を学習する必要があり、最も簡単な方法では不十分です。

于 2012-06-02T21:05:10.767 に答える