Java Utililty Methods Image

List of utility methods to do Image

Description

The list of methods to do Image are organized into topic(s).

Method

ImagecreateTiledImage(Image img, int width, int height)
Crea un 'tiled image' con un objeto image con una anchura y altura
Image image = null;
BufferedImage bimg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
int imageWidth = img.getWidth(null);
int imageHeight = img.getHeight(null);
int numX = (width / imageWidth) + 2;
int numY = (height / imageHeight) + 2;
Graphics2D bGr = bimg.createGraphics();
for (int y = 0; y < numY; y++) {
...
Imagecrop(Image source, int x1, int y1, int x2, int y2)
crop
BufferedImage bi = toBufferedImage(source);
BufferedImage img = bi.getSubimage(x1, y1, x2, y2);
return img;
voiddisplayImage(Image image)
display Image
ImageIcon icon = new ImageIcon(image);
JFrame frame = new JFrame();
frame.setLayout(new FlowLayout());
frame.setSize(image.getWidth(null) + 25, image.getHeight(null) + 50);
JLabel lbl = new JLabel();
lbl.setIcon(icon);
frame.add(lbl);
frame.setVisible(true);
...
voiddisplayImage(Image img)
display Image
JFrame f = new JFrame("DEBUG IMG");
JLabel label = new JLabel(new ImageIcon(img));
label.setBorder(BorderFactory.createLineBorder(Color.RED));
f.setLayout(new BorderLayout());
f.add(label, BorderLayout.WEST);
f.pack();
f.setVisible(true);
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
...
JDialogdisplayImage(Image img, String mesg, int locx, int locy, int sizex, int sizey)
display Image
JDialog imgBox = new JDialog(new java.awt.Frame(), mesg, false);
JPanel imgPanel = new JPanel(new BorderLayout());
imgBox.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
imgBox.setLocation(locx, locy);
imgBox.setSize(sizex, sizey);
imgBox.setContentPane(imgPanel);
ImageIcon imgIcon = new ImageIcon(img, "");
JLabel imgLabel = new JLabel(imgIcon);
...
ListdivideImage(Object obj, int rows, int cols)
divide Image
BufferedImage bi;
if (obj instanceof Image) {
    bi = toBufferedImage((Image) obj);
} else if (obj instanceof ImageIcon) {
    bi = toBufferedImage(((ImageIcon) obj).getImage());
} else {
    bi = (BufferedImage) obj;
int altoBi = bi.getHeight() / rows;
int anchoBi = bi.getWidth() / cols;
List<BufferedImage> imagenes = new ArrayList<>();
BufferedImage subImagen;
for (int f = 0; f < rows; f++) {
    for (int c = 0; c < cols; c++) {
        subImagen = bi.getSubimage(c * anchoBi, f * altoBi, anchoBi, altoBi);
        imagenes.add(subImagen);
return imagenes;
ImageensureImageLoaded(Image img)
Ensures that the image is properly loaded before returning
if (img instanceof BufferedImage) {
    return img;
if (img.getWidth(null) > -1) {
    return img;
if (IMAGE_LOADER == null) {
    IMAGE_LOADER = new ImageIcon();
...
ImagefindImagefromClasspath(Class relToThisClass, String relImageName)
find Imagefrom Classpath
Image image = null;
String name = relToThisClass.getName();
String path = name.substring(0, name.lastIndexOf('.'));
path = path.replace('.', '/');
path = path + relImageName.substring(1); 
String classpath = System.getProperty(CLASSPATH);
StringTokenizer st = new StringTokenizer(classpath, ";:");
while (st.hasMoreTokens()) {
...
JPanelgenerateImageVisualizationPanel(String path, int width, int height, int scaling)
generate Image Visualization Panel
JPanel panel = new JPanel(new BorderLayout());
try {
    Image image = ImageIO.read(new File(path));
    InputStream is = new BufferedInputStream(new FileInputStream(path));
    image = ImageIO.read(is);
    ImageIcon icon = new ImageIcon(path);
    icon.setImage(image);
    JLabel label = new JLabel(icon);
...
ImagegetChatLogoImage(int width, int height)
get Chat Logo Image
return getChatLogoImage().getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING);