Ejemplo n.º 1
1
 /** constructor */
 public DanceQueuePanel() {
   //	flow layout
   setLayout(new FlowLayout());
   //	uses buffer	to	draw arrows	based	on	queues in an array
   myImage = new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB);
   myBuffer = myImage.getGraphics();
   // uses timer to queue buffer changes
   time = 0;
   timer = new Timer(5, new Listener());
   timer.start();
   setFocusable(true);
   // picks instructions	based	on	song & level
   if (Danceoff.getSong() == -1 && Danceoff.getDifficulty() == 0) {
     arrows = new Arrow[] {new UpArrow(1000), new DownArrow(2000), new LeftArrow(3000)};
   }
   // setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK, 3),
   //	"DanceQueuePanel"));
   // load images for arrows
   rightArrowImg = null;
   leftArrowImg = null;
   upArrowImg = null;
   downArrowImg = null;
   try {
     rightArrowImg = ImageIO.read(new File("arrowB right.png"));
     leftArrowImg = ImageIO.read(new File("arrowB left.png"));
     upArrowImg = ImageIO.read(new File("arrowB up copy.png"));
     downArrowImg = ImageIO.read(new File("arrowB down.png"));
   } catch (IOException e) {
     warn("YOU FAIL", e);
     System.exit(2);
   }
 }
Ejemplo n.º 2
0
    private void paintToImage(
        final BufferedImage img, final int x, final int y, final int width, final int height) {
      // clear the prior image
      Graphics2D imgG = (Graphics2D) img.getGraphics();
      imgG.setComposite(AlphaComposite.Clear);
      imgG.setColor(Color.black);
      imgG.fillRect(0, 0, width + blur * 2, height + blur * 2);

      final int adjX = (int) (x + blur + offsetX + (insets.left * distance));
      final int adjY = (int) (y + blur + offsetY + (insets.top * distance));
      final int adjW = (int) (width - (insets.left + insets.right) * distance);
      final int adjH = (int) (height - (insets.top + insets.bottom) * distance);

      // let the delegate paint whatever they want to be blurred
      imgG.setComposite(AlphaComposite.DstAtop);
      if (prePainter != null) prePainter.paint(imgG, adjX, adjY, adjW, adjH);
      imgG.dispose();

      // blur the prior image back into the same pixels
      imgG = (Graphics2D) img.getGraphics();
      imgG.setComposite(AlphaComposite.DstAtop);
      imgG.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
      imgG.setRenderingHint(
          RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
      imgG.drawImage(img, blurOp, 0, 0);

      if (postPainter != null) postPainter.paint(imgG, adjX, adjY, adjW, adjH);
      imgG.dispose();
    }
 public Image getScreenshot() {
   BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
   Graphics g = image.getGraphics();
   paint(g);
   g.dispose();
   return image;
 }
Ejemplo n.º 4
0
  public void generarFondo(Component componente) {
    boolean dibujarFondo = false;
    Rectangle med = this.getBounds();
    Rectangle areaDibujo = this.getBounds();
    BufferedImage tmp;
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();

    if (Principal.fondoBlur) {
      dibujarFondo = true;
    }
    if (dibujarFondo) {
      JRootPane root = SwingUtilities.getRootPane(this);
      blurBuffer = GraphicsUtilities.createCompatibleImage(Principal.sysAncho, Principal.sysAlto);
      Graphics2D g2 = blurBuffer.createGraphics();
      g2.setClip(med);
      blurBuffer = blurBuffer.getSubimage(med.x, med.y, med.width, med.height);
      ((Escritorio) Principal.getEscritorio()).getFrameEscritorio().paint(g2);
      g2.dispose();
      backBuffer = blurBuffer;
      // blurBuffer = toGrayScale(blurBuffer);
      blurBuffer = GraphicsUtilities.createThumbnailFast(blurBuffer, getWidth() / 2);
      blurBuffer = new GaussianBlurFilter(4).filter(blurBuffer, null);
      g2 = (Graphics2D) blurBuffer.getGraphics();
      g2.setColor(new Color(0, 0, 0, 195));
      g2.fillRect(0, 0, Principal.sysAncho, Principal.sysAlto);
      listo = true;
    }
  }
Ejemplo n.º 5
0
 public static BufferedImage copyImage(BufferedImage source) {
   BufferedImage b =
       new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
   Graphics g = b.getGraphics();
   g.drawImage(source, 0, 0, null);
   g.dispose();
   return b;
 }
Ejemplo n.º 6
0
 private void scaleImage() {
   Image img =
       back.getScaledInstance(scx(back.getWidth()), scy(back.getHeight()), Image.SCALE_SMOOTH);
   back =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics g = back.getGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
 }
Ejemplo n.º 7
0
 public static ImageIcon generateIcon(Color _color) {
   int size = (int) (16 * scaleFactor);
   BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
   Graphics2D graphics = (Graphics2D) image.getGraphics();
   graphics.setColor(Color.BLACK);
   graphics.fillRect(0, 0, size, size);
   graphics.setColor(_color);
   graphics.fillRect(1, 1, size - 2, size - 2);
   return new ImageIcon(image);
 }
Ejemplo n.º 8
0
 public void loadImage() throws IOException {
   nonMax = ImageIO.read(new File(path));
   width = nonMax.getWidth();
   height = nonMax.getHeight();
   rmax = width > height ? height / 2 : width / 2;
   accRMax = (rmax + offset - 1) / offset;
   whichRadius.setMaximum(accRMax);
   img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   Graphics g = img.getGraphics();
   g.drawImage(nonMax, 0, 0, null);
   g.dispose();
   res = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   g = res.getGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
   greyScale = copyImage(nonMax);
   ImageIcon icon = new ImageIcon(img);
   ImageIcon icon2 = new ImageIcon(greyScale);
   lbl1.setIcon(icon);
   lbl2.setIcon(icon2);
 }
Ejemplo n.º 9
0
 private static ImageIcon makeRolloverIcon(ImageIcon srcIcon) {
   RescaleOp op =
       new RescaleOp(new float[] {1.2f, 1.2f, 1.2f, 1f}, new float[] {0f, 0f, 0f, 0f}, null);
   BufferedImage img =
       new BufferedImage(
           srcIcon.getIconWidth(), srcIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics g = img.getGraphics();
   // g.drawImage(srcIcon.getImage(), 0, 0, null);
   srcIcon.paintIcon(null, g, 0, 0);
   g.dispose();
   return new ImageIcon(op.filter(img, null));
 }
Ejemplo n.º 10
0
 public static BufferedImage tileImage(BufferedImage im, int width, int height) {
   GraphicsConfiguration gc =
       GraphicsEnvironment.getLocalGraphicsEnvironment()
           .getDefaultScreenDevice()
           .getDefaultConfiguration();
   int transparency = Transparency.OPAQUE; // Transparency.BITMASK;
   BufferedImage compatible = gc.createCompatibleImage(width, height, transparency);
   Graphics2D g = (Graphics2D) compatible.getGraphics();
   g.setPaint(new TexturePaint(im, new Rectangle(0, 0, im.getWidth(), im.getHeight())));
   g.fillRect(0, 0, width, height);
   return compatible;
 }
Ejemplo n.º 11
0
  public void generarFondo(Component componente) {
    Rectangle areaDibujo = this.getBounds();
    BufferedImage tmp;
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();

    tmp = gc.createCompatibleImage(areaDibujo.width, areaDibujo.height, BufferedImage.TRANSLUCENT);
    Graphics2D g2d = (Graphics2D) tmp.getGraphics();
    g2d.setColor(new Color(55, 55, 255, 165));
    g2d.fillRect(0, 0, areaDibujo.width, areaDibujo.height);
    fondo = tmp;
  }
Ejemplo n.º 12
0
 public TransparentWindow(BufferedImage img, int x, int y) {
   image = img;
   try {
     Robot robot = new Robot();
     Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
     screen = robot.createScreenCapture(new Rectangle(0, 0, d.width, d.height));
   } catch (AWTException e) {
     throw new Error(e);
   }
   setBounds(x, y, img.getWidth(), img.getHeight());
   setVisible(true);
   buffer = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
   graphics = (Graphics2D) buffer.getGraphics();
 }
Ejemplo n.º 13
0
  /**
   * Internal utility method that creates a new icon. Called after the user selects a new color, or
   * when the size of the icon changes.
   */
  private void updateIcon() {
    BufferedImage image = new BufferedImage(iconWidth, iconHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) image.getGraphics();

    g2d.setColor(this.color);
    // turn antialiasing off
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    // we want fast rendering
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);

    g2d.fillRect(0, 0, iconWidth, iconHeight);
    ImageIcon imageIcon = new ImageIcon(image);
    this.setIcon(imageIcon);
    g2d.dispose();
  }
Ejemplo n.º 14
0
    SlicedShadowBorder(
        final Painter prePainter,
        final Painter postPainter,
        final int offsetX,
        final int offsetY,
        final float distance,
        final float intensity,
        final int blur,
        final int templateWidth,
        final int templateHeight,
        final int leftCut,
        final int topCut,
        final int rightCut,
        final int bottomCut) {
      super(prePainter, postPainter, offsetX, offsetY, distance, intensity, blur);

      final BufferedImage i =
          new BufferedImage(templateWidth, templateHeight, BufferedImage.TYPE_INT_ARGB_PRE);
      super.paintBorder(null, i.getGraphics(), 0, 0, templateWidth, templateHeight);
      //            debugFrame("slices", i);
      slices = new SlicedImageControl(i, leftCut, topCut, rightCut, bottomCut, false);
    }
Ejemplo n.º 15
0
 BufferedImage createImageFromComponent(Component comp) {
   BufferedImage retImage = null;
   if (comp == null) return retImage;
   try {
     GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
     GraphicsDevice gd = genv.getDefaultScreenDevice();
     GraphicsConfiguration gc = gd.getDefaultConfiguration();
     java.awt.image.ColorModel cm = gc.getColorModel();
     boolean hasAlpha = cm.hasAlpha();
     int cw = comp.getSize().width;
     int ch = comp.getSize().height;
     if (hasAlpha) {
       retImage = gc.createCompatibleImage(cw, ch);
     } else {
       retImage = new BufferedImage(cw, ch, BufferedImage.TYPE_INT_ARGB);
     }
     if (retImage == null) return retImage;
     Graphics og = retImage.getGraphics();
     comp.paint(og);
     og.dispose();
   } catch (Throwable t) {
   }
   return retImage;
 }
Ejemplo n.º 16
0
  protected void filePNG() {

    JFileChooser chooser = null;
    File pngFile = null;
    if (currentFile == null) {
      chooser = new JFileChooser(startDirectory);
    } else {
      pngFile = new File(currentFile.getName() + ".png");
      chooser = new JFileChooser(pngFile);
      if (!currentFile.isDirectory()) {
        chooser.setSelectedFile(currentFile);
      }
    }

    if (pngFile == null) return;
    try {
      BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
      paint(image.getGraphics());
      ImageIO.write(image, "png", pngFile);
    } catch (Exception e) {
    }
    return;
    /*		JFileChooser chooser = null;
    		File pngFile = null;
    		if (currentFile == null) {
    			chooser = new JFileChooser(startDirectory);
    		} else {
    			pngFile = new File(currentFile.getName()+".png");
    			chooser = new JFileChooser(pngFile);
    			if (!currentFile.isDirectory()) {
    				chooser.setSelectedFile(currentFile);
    			}
    		}
    		int returnVal = chooser.showSaveDialog(gw);
    		if (returnVal == JFileChooser.APPROVE_OPTION) {
    			File pngFile = chooser.getSelectedFile();

    			int maxX = Integer.MIN_VALUE;
    			int minX = Integer.MAX_VALUE;
    			int maxY = Integer.MIN_VALUE;
    			int minY = Integer.MAX_VALUE;

    			while(Node node : getNodes()) {
    				if(node.getX() > maxX) {
    					maxX = node.getX();
    				}
    				if(node.getX() < minX) {
    					minX = node.getX();
    				}
    				if(node.getY() > maxY) {
    					maxY = node.getY();
    				}
    				if(node.getY() < minY) {
    					minY = node.getY();
    				}
    			}

    			BufferedImage image = new BufferedImage(maxX-minX+50,maxY-minY+50,BufferedImage.TYPE_INT_RGB);



    			ImageIO.write(image,"png",pngFile);
    		}
    */ }
Ejemplo n.º 17
0
  // Although it presently returns a boolean, that was only needed
  // during my aborted attempted at animated graphics primitives.
  // Until those become a reality the boolean value returned by this
  // routine is unnecessary
  public boolean animate(int sAt, boolean forward) {

    int x;
    LinkedList lt = null;
    animation_done =
        true; // May be re-set in paintComponent via indirect paintImmediately call at end

    // Was used in aborted attempted to
    // introduce animated primitives.  Now
    // it's probably excess baggage that
    // remains because I still have hopes
    // of eventually having animated
    // primitives

    if (getSize().width != 0 && getSize().height != 0) {
      my_width = getSize().width; // set dimensions
      my_height = getSize().height;
    } else {
      my_width = GaigsAV.preferred_width; // set dimensions
      my_height = GaigsAV.preferred_height;
    }

    // First capture the new image in a buffer called image2
    SnapAt = sAt;
    BufferedImage image2 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) image2.getGraphics(); // need a separate object each time?
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    list_of_snapshots.reset();
    x = 0;
    lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    // Next capture the image we are coming from in a buffer called image1
    SnapAt = (forward ? sAt - 1 : sAt + 1);
    BufferedImage image1 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g1 = (Graphics2D) image1.getGraphics(); // need a separate object each time?
    g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g1.setColor(Color.WHITE);
    g1.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    list_of_snapshots.reset();
    x = 0;
    lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g1 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    // Now slide from image1 to image2

    // From the gaff Visualizer by Chris Gaffney
    //        double step = 4;	// Adjust this for more/less granularity between images
    double step = 40; // Adjust this for more/less granularity between images

    Image buffer = getGraphicsConfiguration().createCompatibleVolatileImage(my_width, my_height);
    Graphics2D g2d = (Graphics2D) buffer.getGraphics();

    AffineTransform trans = AffineTransform.getTranslateInstance(step * (forward ? -1 : 1), 0);
    //        AffineTransform orig = g2d.getTransform();

    Shape mask = createMask(my_width, my_height);

    for (double i = 0; i < my_width; i += step) {
      if (i + step > my_width) // last time through loop, so adjust transform
      trans =
            AffineTransform.getTranslateInstance(((double) (my_width - i)) * (forward ? -1 : 1), 0);
      g2d.transform(trans);
      g2d.drawImage(image1, 0, 0, this);
      g2d.setColor(Color.BLACK);
      g2d.fill(mask);

      AffineTransform last = g2d.getTransform();
      g2d.transform(AffineTransform.getTranslateInstance(my_width * (-1 * (forward ? -1 : 1)), 0));
      g2d.drawImage(image2, 0, 0, this);
      g2d.setColor(Color.BLACK);
      g2d.fill(mask);

      g2d.setTransform(last);

      this.my_image = buffer;
      repaint();

      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {

      }
    }
    Image b = getGraphicsConfiguration().createCompatibleImage(my_width, my_height);
    b.getGraphics().drawImage(buffer, 0, 0, null);
    this.my_image = b;

    return animation_done;
  }
Ejemplo n.º 18
0
  // Although it presently returns a boolean, that was only needed
  // during my aborted attempted at animated graphics primitives.
  // Until those become a reality the boolean value returned by this
  // routine is unnecessary
  public /*synchronized*/ boolean execute(int sAt) {

    // The commented-out variables below are remnants from legacy
    // code -- they appear to be no longer needed.

    //         String urlTemp="";
    //         int z=0;
    //         int idx;
    //         int urlid;
    //         boolean showURL=false;
    animation_done =
        true; // May be re-set in paintComponent via indirect paintImmediately call at end

    // Was used in abored attempted to
    // introduce animated primitives.  Now
    // it's probably excess baggage that
    // remains because I still have hopes
    // of eventually having animated
    // primitives
    SnapAt = sAt;

    if (getSize().width != 0 && getSize().height != 0) {
      my_width = getSize().width; // set dimensions
      my_height = getSize().height;
    } else {
      my_width = GaigsAV.preferred_width; // set dimensions
      my_height = GaigsAV.preferred_height;
    }
    BufferedImage buff = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) buff.getGraphics(); // need a separate object each time?
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    // 	if(no_mouse_drag){
    // 	    if(first_paint_call){
    // // 		horizoff = (my_width - (int)(0.25 * my_width) -
    // // 			    GaigsAV.preferred_width) / 2;
    // 		horizoff = (my_width - GaigsAV.preferred_width) / 2;
    // 		first_paint_call = false;
    // 	    }else{
    // 		horizoff = (my_width - GaigsAV.preferred_width) / 2;
    // 		no_mouse_drag = false;
    // 	    }
    // 	}

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    int x;

    list_of_snapshots.reset();
    x = 0;
    LinkedList lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    Shape mask = createMask(buff.getWidth(), buff.getHeight());

    g2.setColor(Color.BLACK);
    g2.fill(mask);

    my_image = buff;
    repaint();

    return animation_done;
  }
Ejemplo n.º 19
0
  private BufferedImage getSpecificImage(
      int x,
      int y,
      int w,
      int h,
      int imgIndexX,
      int imgIndexY,
      BufferedImage buffImg,
      int zoom,
      int cachedZoom,
      GMapListener listener,
      boolean localFilesOnly) {

    int xIndex = x / GDataSource.sourceSize.width;
    int yIndex = y / GDataSource.sourceSize.height;

    xIndex += imgIndexX;
    yIndex += imgIndexY;

    BufferedImage image = null;
    if (!localFilesOnly || getGDataSource().isCached(xIndex, yIndex, zoom))
      image = getIndexedImage(xIndex, yIndex, zoom, cachedZoom, listener);

    int xCoord = x % GDataSource.sourceSize.width;
    int yCoord = y % GDataSource.sourceSize.height;

    // Checks for invalid xCoord and yCoord
    if (xCoord < 0) {
      xCoord = 0;
    }
    if (yCoord < 0) {
      yCoord = 0;
    }

    // get info about the image
    Dimension imageSize =
        new Dimension(getGDataSource().sourceSize.width, getGDataSource().sourceSize.height);

    // find the width of what we CAN paint
    int initPaintWidth = imageSize.width - xCoord;
    int initPaintHeight = imageSize.height - yCoord;

    int paintWidth = initPaintWidth;
    int paintHeight = initPaintHeight;

    int rowImages = numOfRows(x, y, h, zoom, cachedZoom);
    int colImages = numOfCols(x, y, w, zoom, cachedZoom);

    if (imgIndexX >= colImages || imgIndexY >= rowImages) {
      return null;
    }

    int xImage = 0;
    int yImage = 0;

    int xInitCoord = xCoord;
    int yInitCoord = yCoord;

    if (imgIndexX > 0) {
      xImage = initPaintWidth + (imgIndexX - 1) * imageSize.width;
      xCoord = 0;
      if (imgIndexX < (colImages - 1)) {
        paintWidth = imageSize.width;
      } else {
        paintWidth = w - ((colImages - 2) * imageSize.width) - (imageSize.width - xInitCoord);
      }
    }
    if (imgIndexY > 0) {
      yImage = initPaintHeight + (imgIndexY - 1) * imageSize.height;
      yCoord = 0;
      if (imgIndexY < (rowImages - 1)) {
        paintHeight = imageSize.height;
      } else {
        paintHeight = h - ((rowImages - 2) * imageSize.height) - (imageSize.height - yInitCoord);
      }
    }

    if (buffImg != null) {
      Graphics2D g = (Graphics2D) buffImg.getGraphics();
      if (image != null) {
        // System.out.println(xCoord + ":" + yCoord + ":" + paintWidth + ":" + paintHeight);
        g.drawImage(
            image.getSubimage(xCoord, yCoord, paintWidth, paintHeight),
            xImage,
            yImage,
            paintWidth,
            paintHeight,
            null);
      } else {
        Composite originalComposite = g.getComposite();
        g.setComposite(opacity40);
        g.setColor(Color.BLACK);
        g.fillRect(xImage, yImage, paintWidth, paintHeight);
        g.setComposite(originalComposite);
      }
    }

    return buffImg;
  }
Ejemplo n.º 20
0
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == b) {
      JFrame frame2 = new JFrame();
      JFileChooser chooser = new JFileChooser(".");
      int option =
          chooser.showOpenDialog(
              frame2); // parentComponent must a component like JFrame, JDialog...
      if (option == JFileChooser.APPROVE_OPTION) {
        File selectedFile = chooser.getSelectedFile();
        path = selectedFile.getAbsolutePath();
      }
      try {
        loadImage();
      } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
      }
    } else if (e.getSource() == c) {

      gaussianBlur();
      // filtered = grayscale.filter(filtered, null);
      sobel();
      // thinImage();
      nonMax();
      float lowThreshold = 2.5f;
      float highThreshold = 7.5f;
      int low = Math.round(lowThreshold * MAGNITUDE_SCALE);
      int high = Math.round(highThreshold * MAGNITUDE_SCALE);
      performHysteresis(low, high);
      thresholdEdges();
      writeEdges(data);
      Hough();
      ImageIcon icon1 = new ImageIcon(res);
      lbl1.setIcon(icon1);
      ImageIcon icon2 = new ImageIcon(filtered);
      lbl2.setIcon(icon2);
      filterBtn.setSelected(true);
    }
    if (e.getSource() == findCircles) {
      try {
        accSize = Integer.parseInt(inputCircles.getText());
        res = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = res.getGraphics();
        g.drawImage(img, 0, 0, null);
        g.dispose();
        findMaxima();
        ImageIcon icon1 = new ImageIcon(res);
        lbl1.setIcon(icon1);
      } catch (Exception err) {
        System.out.println("Not a valid integer");
      }
    } else if (e.getSource() == filterBtn) {
      ImageIcon icon2 = new ImageIcon(filtered);
      lbl2.setIcon(icon2);
    } else if (e.getSource() == sobelBtn) {
      ImageIcon icon2 = new ImageIcon(sobel);
      lbl2.setIcon(icon2);
    } else if (e.getSource() == nonMaxBtn) {
      ImageIcon icon2 = new ImageIcon(nonMax);
      lbl2.setIcon(icon2);
    } else if (e.getSource() == accumulator) {
      buildAccumulator(whichRadius.getValue());
    }
  }