Exemplo n.º 1
0
  private void createImage2() {
    java.awt.Image img2 = createImage(height, width);
    Graphics g = img2.getGraphics();

    g.setColor(Color.lightGray);
    g.fillRect(0, 0, height, width);

    g.setColor(Color.black);
    FontMetrics fm = g.getFontMetrics();
    String str = "Work Unit keyrate (kkeys/sec)";
    int length = fm.stringWidth(str);
    g.drawString(str, (height / 2) - length / 2, fm.getHeight());
    g.dispose();
    g.finalize();
    img2.flush();

    int[] pixels = new int[height * width];
    PixelGrabber pg = new PixelGrabber(img2, 0, 0, height, width, pixels, 0, height);
    try {
      pg.grabPixels();
    } catch (InterruptedException e) {
      System.err.println("interrupted waiting for pixels!");
      return;
    }

    /* Rotate the Image */
    int pixels2[] = new int[height * width];
    for (int x = 0; x < width; x++)
      for (int y = 0; y < height; y++) {
        int c = pixels[y + (x) * height];

        // Due a bug in the MS-JavaVM the Background for Images are not the same
        // as for Panel's  so. mark it as non-opaque ..
        if (c != 0xff000000) {
          c = 0;
        }
        pixels2[x + (height - y - 1) * width] = c;
      }

    img = createImage(new MemoryImageSource(width, height, pixels2, 0, width));
    repaint();
  }
  public static java.awt.Image ApplyAlphaMask(java.awt.Image original, java.awt.Image alphamask) {
    int width = original.getWidth(null), height = original.getHeight(null);
    if (width <= 0) width = 1;
    if (height <= 0) height = 1;
    BufferedImage resultImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    BufferedImage image = toBufferedImage(original);
    BufferedImage mask = toBufferedImage(alphamask);
    for (int y = 0; y < image.getHeight(null); y++) {
      for (int x = 0; x < image.getWidth(null); x++) {
        try {
          Color c = new Color(image.getRGB(x, y));
          Color maskC = new Color(mask.getRGB(x, y));
          Color maskedColor = new Color(c.getRed(), c.getGreen(), c.getBlue(), maskC.getRed());
          resultImg.setRGB(x, y, maskedColor.getRGB());
        } catch (Exception e) {

        }
      }
    }
    return toImage(resultImg);
  }
Exemplo n.º 3
0
  public static java.awt.image.BufferedImage loadBufferedImageFromResources(
      Component c, String filename) {

    try {
      Misc m = new Misc();
      java.awt.Image img = loadImageFromResources(filename);
      MediaTracker mt = new MediaTracker(c);
      mt.addImage(img, 0);
      mt.waitForID(0);
      int width = img.getWidth(null);
      int height = img.getHeight(null);
      BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      Graphics gg = bi.getGraphics();
      gg.drawImage(img, 0, 0, null);
      gg.dispose();
      return bi;
    } catch (Exception ex) {
      System.out.println(ex.toString());
    }
    return null;
  }