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

📄 wapimage.java

📁 WAP ide 代码
💻 JAVA
字号:
package wbmp;import javax.swing.JComponent;import javax.swing.*;import java.awt.*;import java.awt.image.*;import java.awt.event.*;import java.io.*;/** * Title:        WAPImage * Description:  A class representing a WAPImage. * Copyright:    Copyright (c) 2003 * Company: * @author Mark Busman * @version 1.0 * * For License and contact information see WBMPEditor.java */public class WAPImage implements Icon {  int width, height;  int matrix[][];  Color background;  static Color foreground = new Color(0, 0, 0);  boolean loadedImage = false;  public WAPImage() {    width = 33;    height = 23;  }  public WAPImage(String fname) {    try {      if (fname.equals("")) {        loadedImage = false;      }      else {        Decoder decoder = new Decoder(fname);        loadedImage = true;        width = decoder.getWidth();        height = decoder.getHeight();        matrix = decoder.getMatrix();      }    }    catch (StringIndexOutOfBoundsException strerr) {      loadedImage = false;    }  }  public void setImage(String fname) {    Decoder decoder = new Decoder(fname);    loadedImage = true;    width = decoder.getWidth();    height = decoder.getHeight();    matrix = decoder.getMatrix();  }  public int getIconHeight() {    return height;  }  public int getIconWidth() {    return width;  }  public int[][] getMatrix() {    return matrix;  }  public boolean getImageLoaded() {    return loadedImage;  }  /** Performs the actual drawing on the component.  * @param Graphics g - thegraphics context  */  public void paintIcon(Component c, Graphics g, int lx, int ly) {    //JLabel l = (JLabel) c;    //Color background = l.getBackground();    //g.setColor(background);    //g.fillRect(lx, ly, width, height);    if (!loadedImage) {      //g.setColor(Color.black);      //g.setFont(new Font("custom", Font.PLAIN, 10));      //g.drawString("None", lx + 3, ly + 13);      ImageIcon i = new ImageIcon(wbmp.WBMPEditorFrame.class.getResource("imgTag.gif"));      g.drawImage(i.getImage(), lx, ly, c);      return;    }    for (int x = 0; x < width; x++) {      for (int y = 0; y < height; y++) {        if (matrix[x][y] == 1) {          //g.setColor(background);        }        else {          g.setColor(foreground);          g.drawRect(lx + x, ly + y, 1, 1);          g.fillRect(lx + x, ly + y, 1, 1);        }      }    }  }  public Image getMemoryImage() {    // use memoryimagesource to recreate an image    // use matrix    //int[] pix = new int[1];    //pix[1] = 0;    if (loadedImage) {      int width = getIconWidth();      int height = getIconHeight();      int pos = -1;      int[] pix = new int[width * height];      for (int x = 0; x < width; x++) {        for (int y = 0; y < height; y++) {          pos++;          if (matrix[x][y] == 1) {            int alpha = 0;            alpha <<= 24;            pix[pos] = 0 << 31;          }          else {            pix[pos] = 255 << 24;          }        }      }      return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(width, height, pix, 0, width));    }    ImageIcon i = new ImageIcon(wbmp.WBMPEditorFrame.class.getResource("imgTag.gif"));    return i.getImage();  }}

⌨️ 快捷键说明

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