⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawpane.java~1~

📁 实例19将彩色图像转换为灰度图.rar
💻 JAVA~1~
字号:
package jlookuptabledemo;import java.awt.*;import javax.swing.JPanel;import java.awt.image.*;import java.awt.color.*;public class DrawPane extends JPanel {  private BorderLayout borderLayout1 = new BorderLayout();  Image image;  BufferedImage bimage;  Graphics2D g2D;  public DrawPane() {    try {      jbInit();    }    catch(Exception ex) {      ex.printStackTrace();    }  }  void jbInit() throws Exception {    this.setLayout(borderLayout1);    loadImage();    createBufferedImage();    this.setSize(image.getWidth(this),image.getHeight(this));  }  public void loadImage(){    //image = Toolkit.getDefaultToolkit().createImage("images/image.jpg");   // System.out.println(ClassLoader.getSystemResource("images/image.jpg"));    image = this.getToolkit().createImage(ClassLoader.getSystemResource("images/image.jpg"));    MediaTracker mt = new MediaTracker(this);    mt.addImage(image,0);    try{      mt.waitForAll();    }catch(Exception err){      System.err.println("Could not load the image.");    }    if (image.getWidth(this) == -1){      System.err.println("Could not get the image.");      System.exit(1);    }  }  public void createBufferedImage(){    bimage = new BufferedImage(image.getWidth(this),image.getHeight(this),        BufferedImage.TYPE_INT_ARGB);    g2D = bimage.createGraphics();    g2D.drawImage(image,0,0,this);  }  public void reset(){    g2D.setColor(Color.black);    g2D.clearRect(0,0,image.getWidth(this),image.getHeight(this));    g2D.drawImage(image,0,0,this);  }  public void grayOut(){    ColorConvertOp cco = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY),null);    cco.filter(bimage,bimage);  }  public void update(Graphics g){    g.clearRect(0,0,this.getWidth(),this.getHeight());    paintComponent(g);  }  public void paintComponent(Graphics g){    super.paintComponent(g);    Graphics2D g2 = (Graphics2D)g;    g2.drawImage(bimage,0,0,this);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -