Java Image File Check isImage(InputStream is)

Here you can find the source of isImage(InputStream is)

Description

is Image

License

Open Source License

Declaration

public static final boolean isImage(InputStream is) 

Method Source Code


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

import java.awt.image.BufferedImage;
import java.io.*;

import javax.imageio.ImageIO;

public class Main {
    public static final boolean isImage(InputStream is) {
        boolean ret = false;

        try {/*from   w w w  . j a  v a2 s  .  co m*/
            BufferedImage bufreader = ImageIO.read(is);
            int width = bufreader.getWidth();
            int height = bufreader.getHeight();
            if (width == 0 || height == 0) {
                ret = false;
            } else {
                ret = true;
            }
        } catch (IOException e) {
            ret = false;
        } catch (Exception e) {
            ret = false;
        }

        return ret;
    }
}

Related

  1. isImage(File imageFile)
  2. isImage(File img)
  3. isImage(File imgFile)