Ejemplo n.º 1
0
  // temp jpanel stuff to display image
  public void paint(Graphics g) {

    // System.out.println("painting now");
    int charWidth = 10;

    String aMessage = "you can always spot the equinoxes";
    aMessage = aMessage.toLowerCase();

    for (int charNum = 0; charNum < 39; charNum++) {
      if (charNum < aMessage.length()) {
        char c = aMessage.charAt(charNum);
        // int thecharint = (int)c;
        // System.out.println(c);
        g.drawImage(fontStandard.getLetterformImg(c), charNum * charWidth, 0, null);
      } else {
        g.drawImage(fontStandard.getLetterformImg(' '), charNum * charWidth, 0, null);
      }
    }
  }
  public void generateTextImage() {
    BufferedImage tempImage =
        new BufferedImage(text.length() * 10, 14, BufferedImage.TYPE_INT_ARGB);
    Graphics tig = tempImage.getGraphics();

    for (int i = 0; i < text.length(); i++) {
      BufferedImage bi = font.getLetterformImg(text.charAt(i));
      tig.drawImage(bi, i * 10, 0, null);
    }

    // set color of text image
    int xOffset = 0;
    int colorInt = c.getRGB();
    for (int x = 0; x < tempImage.getWidth(); x++) {
      int curX = xOffset + x;
      for (int y = 0; y < tempImage.getHeight(); y++) {
        if (tempImage.getRGB(x, y) == -1) {
          tempImage.setRGB(curX, y, colorInt);
        }
      }
    }

    textImage = tempImage;
  }