Example usage for javax.swing ImageIcon paintIcon

List of usage examples for javax.swing ImageIcon paintIcon

Introduction

In this page you can find the example usage for javax.swing ImageIcon paintIcon.

Prototype

public synchronized void paintIcon(Component c, Graphics g, int x, int y) 

Source Link

Document

Paints the icon.

Usage

From source file:com.uksf.mf.core.utility.loaders.ImageLoad.java

/**
 * Changes colour of all non-transparent pixels for given image to given colour
 * @param image - image to change colours in
 * @param newColour colour to change to/*from   w  w w . ja  v  a 2  s. c o  m*/
 * @return image with changed colours
 */
private static ImageIcon changeImageColour(ImageIcon image, int newColour) {
    LogHandler.logSeverity(INFO, "Converting image: " + image + " colour to: " + newColour);
    BufferedImage bufferedImage = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics graphics = bufferedImage.createGraphics();
    image.paintIcon(null, graphics, 0, 0);
    graphics.dispose();
    for (int x = 0; x < bufferedImage.getWidth(); x++) {
        for (int y = 0; y < bufferedImage.getHeight(); y++) {
            int colour = bufferedImage.getRGB(x, y);
            colour = (((colour >> 24) & 0xff) << 24) | (((colour & 0x00ff0000) >> 16) << 16)
                    | (((colour & 0x0000ff00) >> 8) << 8) | (colour & 0x000000ff);
            if (colour != COLOUR_TRANSPARENT.getRGB()) {
                newColour = (((colour >> 24) & 0xff) << 24) | (((newColour & 0x00ff0000) >> 16) << 16)
                        | (((newColour & 0x0000ff00) >> 8) << 8) | (newColour & 0x000000ff);
                bufferedImage.setRGB(x, y, newColour);
            }
        }
    }
    return new ImageIcon(bufferedImage);
}

From source file:BasicDraw.java

public void paint(Graphics g) {

    ImageIcon icon = new ImageIcon("a.png");
    int x = 0;//from w  w w .j a  v a 2  s  .  co  m
    int y = 100;
    icon.paintIcon(this, g, x, y);
}

From source file:examples.gp.monalisa.gui.GeneticDrawingView.java

public GeneticDrawingView(SingleFrameApplication app) {
    super(app);/*from   w ww  .jav a 2s.  c  o  m*/
    initComponents();
    ResourceMap resourceMap = getResourceMap();
    ImageIcon imageIcon = resourceMap.getImageIcon("targetImageLabel.icon");
    targetImage = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    imageIcon.paintIcon(null, targetImage.getGraphics(), 0, 0);
    fittestDrawingView = new FittestDrawingView();
    fittestDrawingView.setVisible(false);
    fittestDrawingView.setSize(targetImage.getWidth(), targetImage.getHeight());
}

From source file:gd.gui.GeneticDrawingView.java

public GeneticDrawingView(SingleFrameApplication app) {
    super(app);/*from  ww w . ja  v a 2  s.  co m*/

    initComponents();

    ResourceMap resourceMap = getResourceMap();
    ImageIcon imageIcon = resourceMap.getImageIcon("targetImageLabel.icon");
    targetImage = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    imageIcon.paintIcon(null, targetImage.getGraphics(), 0, 0);
    ProblemInstance.currentImage = targetImage;
    ProblemInstance.view = this;

    fittestDrawingView = new FittestDrawingView();
    fittestDrawingView.setVisible(false);
    fittestDrawingView.setSize(targetImage.getWidth(), targetImage.getHeight());

    try {
        startEvolution();
    } catch (InvalidConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:com.t3.model.Token.java

private Asset createAssetFromIcon(ImageIcon icon) {
    if (icon == null)
        return null;

    // Make sure there is a buffered image for it
    Image image = icon.getImage();
    if (!(image instanceof BufferedImage)) {
        image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), Transparency.TRANSLUCENT);
        Graphics2D g = ((BufferedImage) image).createGraphics();
        icon.paintIcon(null, g, 0, 0);
    }/*  w  w w  .  j a v a2s  .c o  m*/
    // Create the asset
    Asset asset = null;
    try {
        asset = new Asset(name, ImageUtil.imageToBytes((BufferedImage) image));
        if (!AssetManager.hasAsset(asset))
            AssetManager.putAsset(asset);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return asset;
}

From source file:util.io.IOUtilities.java

/**
 * Writes the given image icon to the given file in the given imageType.
 *
 * @param icon The icon to write./*from   ww w.ja va2s .  c om*/
 * @param imageType The image type.
 * @param targetFile The file to write the image to.
 *
 * @return <code>True</code> if the file could be written, <code>false</code> if something went wrong.
 * @since 2.6
 */
public static boolean writeImageIconToFile(ImageIcon icon, String imageType, File targetFile) {
    try {
        BufferedImage iconimage = new BufferedImage(icon.getIconWidth(), icon.getIconWidth(),
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = iconimage.createGraphics();
        icon.paintIcon(null, g2, 0, 0);
        g2.dispose();

        ImageIO.write(iconimage, imageType, targetFile);
    } catch (Exception e) {
        return false;
    }

    return true;
}