Example usage for javax.imageio ImageIO read

List of usage examples for javax.imageio ImageIO read

Introduction

In this page you can find the example usage for javax.imageio ImageIO read.

Prototype

public static BufferedImage read(ImageInputStream stream) throws IOException 

Source Link

Document

Returns a BufferedImage as the result of decoding a supplied ImageInputStream with an ImageReader chosen automatically from among those currently registered.

Usage

From source file:Main.java

ImagePanel(String name) {
    super(true);/*from  ww w .j a v a  2  s  .  c o  m*/
    try {
        img = ImageIO.read(new File(name));
        this.setPreferredSize(new Dimension(img.getWidth(), img.getHeight()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.spstudio.common.image.ImageUtils.java

public static String cutImage(String sourcePath, String targetPath, int x, int y, int width, int height)
        throws IOException {
    File imageFile = new File(sourcePath);
    if (!imageFile.exists()) {
        throw new IOException("Not found the images:" + sourcePath);
    }/*  w  w  w  .j  a v a2s . c  o m*/
    if (targetPath == null || targetPath.isEmpty()) {
        targetPath = sourcePath;
    }
    String format = sourcePath.substring(sourcePath.lastIndexOf(".") + 1, sourcePath.length());
    BufferedImage image = ImageIO.read(imageFile);
    image = image.getSubimage(x, y, width, height);
    ImageIO.write(image, format, new File(targetPath));
    return targetPath;
}

From source file:com.dfki.av.sudplan.Configuration.java

/**
 * Initialize the {@link #SUDPLAN_3D_IMAGE}.
 *
 * @return the {@link Image} to return or null.
 *//*from   w  w w  .  j a va 2 s .  co m*/
private static Image initImage() {
    log.info("Init suplan3D icon...");
    Image image = null;
    try {
        ClassLoader loader = Configuration.class.getClassLoader();
        URL iconURL = loader.getResource("icons/sudplan3D.png");
        image = ImageIO.read(iconURL);
    } catch (IOException ex) {
        log.error(ex.toString());
    }

    return image;
}

From source file:Main.java

public Panel() {
    try {/*w  ww  .  j a  v a  2s  . co m*/
        image = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.googlecode.fightinglayoutbugs.helpers.ImageHelper.java

public static BufferedImage urlToImage(URL imageUrl) {
    BufferedImage image;/* w ww . ja  va2s  .  co m*/
    try {
        image = ImageIO.read(imageUrl);
    } catch (IOException e) {
        throw new RuntimeException("Failed to read image from URL: " + imageUrl, e);
    }
    return image;
}

From source file:com.buddycloud.mediaserver.business.util.ImageUtils.java

public static BufferedImage createImagePreview(File image, int size) throws IOException {
    final BufferedImage img = ImageIO.read(image);
    final BufferedImage thumbnail = Scalr.resize(img, Method.ULTRA_QUALITY, size);
    img.flush();/*from  ww w .  j  a v a2  s. c  o  m*/

    return thumbnail;
}

From source file:Main.java

public WatermarkTextField(URL file) {
    super();/*w  w  w.j  a  v  a  2s . c  om*/
    try {
        img = ImageIO.read(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Rectangle rect = new Rectangle(0, 0, img.getWidth(null), img.getHeight(null));
    texture = new TexturePaint(img, rect);
    setOpaque(false);
}

From source file:com.l1j5.web.common.utils.ImageUtils.java

public static void getImageThumbnail(BufferedInputStream stream_file, String save, String type, int w, int h) {

    try {//ww w .j  ava2s  .  c  o  m
        File file = new File(save);
        BufferedImage bi = ImageIO.read(stream_file);

        int width = bi.getWidth();
        int height = bi.getHeight();
        if (w < width) {
            width = w;
        }
        if (h < height) {
            height = h;
        }

        BufferedImage bufferIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Image atemp = bi.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING);

        Graphics2D g2 = bufferIm.createGraphics();
        g2.drawImage(atemp, 0, 0, width, height, null);
        ImageIO.write(bufferIm, type, file);
    } catch (Exception e) {
        log.error(e);
    }

}

From source file:Main.java

public TestPane() {
    try {//from  w  w  w  .  j a v  a 2  s. c  o m
        myImage = ImageIO.read(new File("test.png"));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:ScrollPaneWatermark.java

public void setBackgroundTexture(URL url) throws IOException {
    bgimage = ImageIO.read(url);
    Rectangle rect = new Rectangle(0, 0, bgimage.getWidth(null), bgimage.getHeight(null));
    texture = new TexturePaint(bgimage, rect);
}