我想用java编一程序,读取jpg文件并显示。望得到较好的方法!不知能不能使用BufferedImage。先谢谢了!

解决方案 »

  1.   

    别人写的将JEditorPane透明就可以看到下面组件上绘的图了。import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;public class Test extends JFrame {
      JPanel pane;
      JEditorPane text;
      Image image;  public Test() {
        super("背景");
        this.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent windowEvent) {
            System.exit(0);
          }
        });
        String url = "http://images.csdn.net/20041202/sms3.JPG";
        try {
          image = (new ImageIcon(new URL(url))).getImage();
          text = new JEditorPane();
          text.setOpaque(false);
          pane = new JPanel() {
            public void paintComponent(Graphics g) {
              g.drawImage(image, 0, 0, this);
            }
          };
          pane.setLayout(new BorderLayout());
          pane.add(text);
        }
        catch (MalformedURLException ex) {
        }
        this.getContentPane().add(pane);
        this.setSize(200, 150);
        this.setVisible(true);
      }
      public static void main(String[] args) {
        new Test();
      }
    }
      

  2.   

    sorry,问题没有表述清楚,我想读的图片是非常大的(如10000*8000),总是出现OutOfMemoryError,试过修改-Xms 和 -Xmx 都不是很管用,希望得到指教!