?? drawpane.java~4~
字號:
package jlookuptabledemo;import java.awt.*;import javax.swing.JPanel;import java.awt.image.*;public class DrawPane extends JPanel { private BorderLayout borderLayout1 = new BorderLayout(); Image image; BufferedImage bimage; Graphics2D g2D; LookupTable LUT; 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"); image = this.getToolkit().createImage(ClassLoader.getSystemResource("images/images.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 brightenLUT(){ short[] brighten = new short[256]; short pixelValue; for (int i=0;i<256;i++){ pixelValue = (short)(i+10); if (pixelValue>255) pixelValue = 255; else if (pixelValue <0) pixelValue =0; brighten[i] = pixelValue; } LUT = new ShortLookupTable(0,brighten); } public void darkenLUT(){ short[] darken = new short[256]; short pixelValue; for (int i=0;i<256;i++){ pixelValue = (short)(i-10); if (pixelValue>255) pixelValue = 255; else if (pixelValue <0) pixelValue =0; darken[i] = pixelValue; } LUT = new ShortLookupTable(0,darken); } 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 applyFilter(){ LookupOp lop = new LookupOp(LUT,null); lop.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 + -