Ejemplo n.º 1
0
  public getPicInfo(Frame father) {
    try {
      FileDialog diag = new FileDialog(father);
      diag.setVisible(true);
      m_Img =
          getToolkit()
              .getImage(diag.getDirectory() + diag.getFile())
              .getScaledInstance(W, H, Image.SCALE_SMOOTH);
      MediaTracker mt = new MediaTracker(this);
      mt.addImage(m_Img, 0);
      mt.waitForAll();
      PixelGrabber grab = new PixelGrabber(m_Img, 0, 0, W, H, m_Pix, 0, W);
      grab.grabPixels();
      m_ImgSrc = new MemoryImageSource(W, H, m_Pix, 0, W);
      m_Img = createImage(m_ImgSrc);
      System.out.println("Wait HERE !");
    } catch (InterruptedException e) {

    }
  }
Ejemplo n.º 2
0
  public void init() {
    MediaTracker mt = new MediaTracker(this);

    URL url = getClass().getResource("tiger.gif");

    try {
      image = createImage((ImageProducer) url.getContent());
      mt.addImage(image, 0);
      mt.waitForID(0);
    } catch (Exception e) {
      e.printStackTrace();
    }
    imw = image.getWidth(this);
    imh = image.getWidth(this);
    pixels = new int[imw * imh];

    try {
      PixelGrabber pg = new PixelGrabber(image, 0, 0, imw, imh, pixels, 0, imw);
      pg.grabPixels();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseMoved(MouseEvent e) {
            int mx = e.getX(), my = e.getY();

            if (mx > 0 && mx < imw && my > 0 && my < imh) {
              int pixel = ((int[]) pixels)[my * imw + mx];

              int red = defaultRGB.getRed(pixel),
                  green = defaultRGB.getGreen(pixel),
                  blue = defaultRGB.getBlue(pixel),
                  alpha = defaultRGB.getAlpha(pixel);

              showStatus("red=" + red + " green=" + green + " blue=" + blue + " alpha=" + alpha);
            }
          }
        });
  }
Ejemplo n.º 3
0
  private static int[] makeGradientPallet() {
    BufferedImage image = new BufferedImage(100, 1, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    Point2D start = new Point2D.Float(0f, 0f);
    Point2D end = new Point2D.Float(99f, 0f);
    float[] dist = {0f, .5f, 1f};
    Color[] colors = {Color.RED, Color.YELLOW, Color.GREEN};
    g2.setPaint(new LinearGradientPaint(start, end, dist, colors));
    g2.fillRect(0, 0, 100, 1);
    g2.dispose();

    int width = image.getWidth(null);
    int[] pallet = new int[width];
    PixelGrabber pg = new PixelGrabber(image, 0, 0, width, 1, pallet, 0, width);
    try {
      pg.grabPixels();
    } catch (InterruptedException ex) {
      ex.printStackTrace();
    }
    return pallet;
  }
Ejemplo n.º 4
0
  /** *************** Grab Pixels and Convert to gray scale ************** */
  int[] pixel_grab(Image img, int width, int height) {
    int pixSrc[] = new int[w * h];
    try {
      PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pixSrc, 0, w);
      pg.grabPixels();
    } catch (Exception e) {
      System.out.println("Exception at Pixel Grabbing");
    }

    for (int i = 0; i < w * h; i++) //  Convertion of pixle form to normal single Value...
    {
      int a = pixSrc[i];
      int r = (0xff & (a >> 16));
      int g = (0xff & (a >> 8));
      int b = (0xff & a);
      int avg = (int) ((.33 * r + .56 * g + .11 * b)); // Add a constant to each pixel
      pixSrc[i] = avg;
    }

    return (pixSrc);
  }