public void gaussianBlur() {
   filtered = null;
   // Kernel kernel = new Kernel(5, 5, makeGaussianKernel(5, 1.4f));
   Kernel kernel = new Kernel(5, 5, gaus);
   ConvolveOp op = new ConvolveOp(kernel);
   filtered = op.filter(greyScale, null);
   ImageIcon icon2 = new ImageIcon(filtered);
   lbl2.setIcon(icon2);
 }
示例#2
0
 private static BufferedImage applyKernelFilter(final BufferedImage source, Kernel customFilter)
     throws IOException, NullPointerException {
   if (verifyNotNull(source)) {
     RenderingHints requiredRenderingHintsForQuality =
         new RenderingHints(
             generateRenderingHintsBasedOnProperties(ImageProcessing.HIGH_BEST_SLOW));
     ConvolveOp bufferedImageOperations =
         new ConvolveOp(customFilter, ConvolveOp.EDGE_NO_OP, requiredRenderingHintsForQuality);
     BufferedImage target =
         new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
     target = bufferedImageOperations.filter(source, target);
     if (verifyNotNull(target)) {
       return target;
     }
     throw new NullPointerException("Internal: Target was null");
   }
   throw new NullPointerException(E_OBJECT_WAS_NULL);
 }
示例#3
0
  static void paintShadowTitle(
      Graphics g,
      String title,
      int x,
      int y,
      Color frente,
      Color shadow,
      int desp,
      int tipo,
      int orientation) {

    // Si hay que rotar la fuente, se rota
    Font f = g.getFont();
    if (orientation == SwingConstants.VERTICAL) {
      AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
      f = f.deriveFont(rotate);
    }

    // Si hay que pintar sombra, se hacen un monton de cosas
    if (shadow != null) {
      int matrix = (tipo == THIN ? MATRIX_THIN : MATRIX_FAT);

      Rectangle2D rect = g.getFontMetrics().getStringBounds(title, g);

      int w, h;
      if (orientation == SwingConstants.HORIZONTAL) {
        w = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde
        h = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP
      } else {
        h = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde
        w = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP
      }

      // La sombra del titulo
      BufferedImage iTitulo = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
      BufferedImage iSombra = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

      Graphics2D g2 = iTitulo.createGraphics();
      g2.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

      g2.setFont(f);
      g2.setColor(shadow);
      g2.drawString(title, 3 * matrix, 3 * matrix); // La pintamos en el centro

      ConvolveOp cop =
          new ConvolveOp((tipo == THIN ? kernelThin : kernelFat), ConvolveOp.EDGE_NO_OP, null);
      cop.filter(iTitulo, iSombra); // A ditorsionar

      // Por fin, pintamos el jodio titulo
      g.drawImage(
          iSombra,
          x - 3 * matrix + desp, // Lo llevamos a la posicion original y le sumamos 1
          y - 3 * matrix + desp, // para que la sombra quede pelin desplazada
          null);
    }

    // Si hay que pintar el frente, se pinta
    if (frente != null) {
      g.setFont(f);
      g.setColor(frente);
      g.drawString(title, x, y);
    }
  }