Java BufferedImage Load loadImage(String i, int x, int imageWidth, int imageHeight)

Here you can find the source of loadImage(String i, int x, int imageWidth, int imageHeight)

Description

load Image

License

Open Source License

Declaration

public static BufferedImage loadImage(String i, int x, int imageWidth, int imageHeight) 

Method Source Code


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

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Main {
    public static BufferedImage loadImage(String i, int x, int imageWidth, int imageHeight) {
        try {// w  w w  .  j  av  a  2s  . c  om
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice gs = ge.getDefaultScreenDevice();
            GraphicsConfiguration gc = gs.getDefaultConfiguration();
            BufferedImage tempBuff = ImageIO.read(new File(i));
            BufferedImage a = gc.createCompatibleImage(imageWidth, imageHeight, Transparency.TRANSLUCENT);
            Graphics tempG = a.getGraphics();
            tempG.drawImage(tempBuff.getSubimage(x, 0, imageWidth, imageHeight), 0, 0, null);
            tempG.dispose();
            return a;

        } catch (IOException ioexception) {
            return null;
        }

    }
}

Related

  1. loadImage(String filename)
  2. loadImage(String fileName)
  3. loadImage(String fileName, Component c)
  4. loadImage(String fileName, Component component)
  5. loadImage(String filePath)
  6. loadImage(String image)
  7. loadImage(String imageName)
  8. loadImage(String imageName, Component c)
  9. loadImage(String path)