コード例 #1
0
ファイル: IconIO.java プロジェクト: munix/jdget
 /**
  * @param resource
  * @param i
  * @return
  */
 public static ImageIcon getImageIcon(final URL resource, final int size) {
   if (size <= 0) {
     return new ImageIcon(IconIO.getImage(resource));
   } else {
     return new ImageIcon(
         IconIO.getScaledInstance(
             IconIO.getImage(resource), size, size, Interpolation.BICUBIC, true));
   }
 }
コード例 #2
0
ファイル: DomainInfo.java プロジェクト: Irbidan/jdownloader
 /**
  * returns a high quality icon for this domain. most domains do not support this and will return
  * null; the icon is NOT cached. use with care
  *
  * @param i
  * @return
  */
 public Icon getIcon(int size) {
   Icon ret = null;
   if (NewTheme.I().hasIcon("fav/big." + getTld())) {
     ret = NewTheme.I().getIcon("fav/big." + getTld(), -1);
   }
   if (ret == null && NewTheme.I().hasIcon("fav/" + getTld())) {
     ret = NewTheme.I().getIcon("fav/" + getTld(), -1);
   }
   if (ret != null && ret.getIconHeight() >= size && ret.getIconWidth() >= size) {
     return IconIO.getScaledInstance(ret, size, size);
   }
   ret = FavIcons.getFavIcon(getTld(), null);
   if (ret.getIconHeight() >= size && ret.getIconWidth() >= size) {
     return IconIO.getScaledInstance(ret, size, size);
   }
   return null;
 }
コード例 #3
0
ファイル: IconIO.java プロジェクト: munix/jdget
  /**
   * @param object
   * @param image
   * @param i
   * @param j
   * @return
   * @return
   */
  public static BufferedImage paint(
      final BufferedImage paintTo, final Image image, final int xoffset, final int yoffset) {

    final Graphics2D g2 = paintTo.createGraphics();
    g2.drawImage(image, xoffset, yoffset, null);
    g2.dispose();
    IconIO.debug(paintTo);
    return paintTo;
  }
コード例 #4
0
ファイル: IconIO.java プロジェクト: munix/jdget
 /**
  * @param ico
  * @return
  */
 public static ImageIcon toImageIcon(final Icon icon) {
   if (icon == null) {
     return null;
   }
   if (icon instanceof ImageIcon) {
     return (ImageIcon) icon;
   } else {
     return new ImageIcon(IconIO.toBufferedImage(icon));
   }
 }
コード例 #5
0
ファイル: DomainInfo.java プロジェクト: Irbidan/jdownloader
 public Icon setFavIcon(Icon icon) {
   if (icon == null) {
     icon = hosterIcon;
     if (icon != null) {
       return icon;
     }
     icon = FavIcons.getFavIcon(getTld(), this);
   }
   if (icon != null) {
     icon = IconIO.getScaledInstance(icon, WIDTH, HEIGHT, Interpolation.BICUBIC);
   }
   hosterIcon = icon;
   return icon;
 }
コード例 #6
0
ファイル: IconIO.java プロジェクト: munix/jdget
  /**
   * This function removes the major color of the image and replaces it with transparency.
   *
   * @param image
   * @return
   */
  public static BufferedImage removeBackground(final BufferedImage image, final double tollerance) {

    final HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    int biggestValue = 0;
    int color = -1;
    for (final int rgb :
        image.getRGB(
            0, 0, image.getWidth() - 1, image.getHeight() - 1, null, 0, image.getWidth())) {
      Integer v = map.get(rgb);
      if (v == null) {
        v = 0;
      }
      v++;
      map.put(rgb, v);
      if (v > biggestValue) {
        biggestValue = v;
        color = rgb;
      }
    }
    final Color col = new Color(color);

    final int r = col.getRed();
    final int g = col.getGreen();
    final int b = col.getBlue();
    final int a = col.getAlpha();
    return IconIO.colorRangeToTransparency(
        image,
        new Color(
            Math.max((int) (r * (1d - tollerance)), 0),
            Math.max((int) (g * (1d - tollerance)), 0),
            Math.max((int) (b * (1d - tollerance)), 0),
            a),
        new Color(
            Math.min(255, (int) (r * (1d + tollerance))),
            Math.min(255, (int) (g * (1d + tollerance))),
            Math.min(255, (int) (b * (1d + tollerance))),
            a));
  }
コード例 #7
0
ファイル: IconIO.java プロジェクト: munix/jdget
  public static BufferedImage colorRangeToTransparency(
      final BufferedImage image, final Color c1, final Color c2) {

    final int r1 = c1.getRed();
    final int g1 = c1.getGreen();
    final int b1 = c1.getBlue();
    final int r2 = c2.getRed();
    final int g2 = c2.getGreen();
    final int b2 = c2.getBlue();
    final ImageFilter filter =
        new RGBImageFilter() {
          @Override
          public final int filterRGB(final int x, final int y, final int rgb) {

            final int r = (rgb & 0xFF0000) >> 16;
            final int g = (rgb & 0xFF00) >> 8;
            final int b = rgb & 0xFF;
            if (r >= r1 && r <= r2 && g >= g1 && g <= g2 && b >= b1 && b <= b2) {
              // Set fully transparent but keep color
              // calculate a alpha value based on the distance between the
              // range borders and the pixel color
              final int dist =
                  (Math.abs(r - (r1 + r2) / 2)
                          + Math.abs(g - (g1 + g2) / 2)
                          + Math.abs(b - (b1 + b2) / 2))
                      * 2;

              return new Color(r, g, b, Math.min(255, dist)).getRGB();
            }

            return rgb;
          }
        };

    final ImageProducer ip = new FilteredImageSource(image.getSource(), filter);
    final Image img = Toolkit.getDefaultToolkit().createImage(ip);
    return IconIO.toBufferedImage(img);
  }
コード例 #8
0
ファイル: IconIO.java プロジェクト: munix/jdget
  /**
   * @param image
   * @param f
   * @return
   */
  public static ImageIcon getTransparentIcon(final Image src, final float f) {

    return new ImageIcon(IconIO.getTransparent(src, f));
  }
コード例 #9
0
ファイル: IconIO.java プロジェクト: munix/jdget
 /**
  * @param image
  * @param i
  * @param j
  * @return
  */
 public static BufferedImage getScaledInstance(
     final Image img, final int width, final int height) {
   // TODO Auto-generated method stub
   return IconIO.getScaledInstance(img, width, height, Interpolation.BICUBIC, true);
 }
コード例 #10
0
ファイル: IconIO.java プロジェクト: munix/jdget
 public static Icon getScaledInstance(final Icon icon, final int width, final int height) {
   // TODO Auto-generated method stub
   return IconIO.getScaledInstance(icon, width, height, Interpolation.BICUBIC);
 }
コード例 #11
0
ファイル: IconIO.java プロジェクト: munix/jdget
  /**
   * @param resource
   * @return
   */
  public static ImageIcon getImageIcon(final URL resource) {

    return new ImageIcon(IconIO.getImage(resource));
  }
コード例 #12
0
ファイル: IconIO.java プロジェクト: munix/jdget
 /**
  * @param resource
  * @return
  */
 public static BufferedImage getImage(final URL resource) {
   return IconIO.getImage(resource, true);
 }