Java ImageIcon createOverlayIcon(Icon baseIcon, ImageIcon overlayIcon)

Here you can find the source of createOverlayIcon(Icon baseIcon, ImageIcon overlayIcon)

Description

create Overlay Icon

License

Open Source License

Declaration

public static ImageIcon createOverlayIcon(Icon baseIcon, ImageIcon overlayIcon) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Graphics2D;
import java.awt.Image;

import java.awt.image.BufferedImage;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Main {
    public static ImageIcon createOverlayIcon(Icon baseIcon, ImageIcon overlayIcon) {
        BufferedImage result = new BufferedImage(baseIcon.getIconWidth(), baseIcon.getIconHeight(),
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = result.createGraphics();
        baseIcon.paintIcon(null, g2, 0, 0);

        Image overlay = overlayIcon.getImage();

        int w = 12;
        int h = 12;
        int x = baseIcon.getIconWidth() - w;
        int y = baseIcon.getIconHeight() - h;

        g2.drawImage(overlay, x, y, x + w, y + w, 0, 0, overlayIcon.getIconWidth(), overlayIcon.getIconHeight(),
                null);//from   w  w  w .  j  a  v a 2 s. c  o  m

        g2.dispose();

        return new ImageIcon(result);
    }
}

Related

  1. createDisabledImage(final ImageIcon imageIcon)
  2. createEmptyImageIcon(final int width, final int height)
  3. createFileImageIcon(final String path)
  4. createMonoColoredImageIcon(final Paint paint, final int width, final int height)
  5. createNonCachedImageIcon(File file)
  6. createScaledImageIcon(byte[] albumArtBytes)
  7. CreateSizedImageIconScaledSmooth(URL filePath, int width, int height)
  8. createTempImage(ImageIcon icon, File oldFile)
  9. displayImage(final ImageIcon ii)