Java Image getManagedImage(Component source, String file, float tint, Color solid)

Here you can find the source of getManagedImage(Component source, String file, float tint, Color solid)

Description

gets a managed image with the specified alpha tinting and all that jazz

License

Artistic License

Declaration

public static Image getManagedImage(Component source, String file, float tint, Color solid) 

Method Source Code


//package com.java2s;
//License from project: Artistic License 

import java.awt.*;

import java.io.*;

public class Main {
    /** gets a managed image with the specified alpha tinting and all that jazz */
    public static Image getManagedImage(Component source, String file, float tint, Color solid) {
        if (!(new File(file)).exists()) {
            return null;
        }//from www  .j a v  a  2s. c o  m

        Image imageData = new javax.swing.ImageIcon(file).getImage();

        if (tint > 0) {
            Image imageDataTinted = source.createImage(imageData.getWidth(null), imageData.getHeight(null));

            Graphics2D g2 = (Graphics2D) imageDataTinted.getGraphics();
            Composite oc = g2.getComposite();

            g2.drawImage(imageData, 0, 0, null);

            AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, tint);
            g2.setComposite(ac);
            g2.setColor(solid);
            g2.fillRect(0, 0, imageDataTinted.getWidth(null), imageDataTinted.getHeight(null));

            g2.dispose();

            return imageDataTinted;
        }

        return imageData;
    }
}

Related

  1. getImageImmediate(final Image image)
  2. GetImagenConTamanioDado(File file, int ancho, int alto)
  3. getImageWithBorder(Image imagen)
  4. getInputStreamFromImage(Image imagen, String format)
  5. getLogoImage()
  6. getNewImageFileChooser()
  7. getOpenSwingImage(String name)
  8. getPanelImage(JPanel p)
  9. getScreenShareImage()