Java Image File Check isImage(File img)

Here you can find the source of isImage(File img)

Description

is Image

License

Apache License

Declaration

public static boolean isImage(File img) 

Method Source Code

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

import java.awt.Image;

import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Main {

    public static boolean isImage(File img) {
        try {//from  w  w  w  .  ja  v a 2  s  .  c  o m
            return isImage(ImageIO.read(img));
        } catch (IOException e) {
            return false;
        }
    }

    public static boolean isImage(Image img) {
        return img != null && img.getWidth(null) > -1 && img.getHeight(null) > -1;
    }
}

Related

  1. isImage(File imageFile)
  2. isImage(File imgFile)
  3. isImage(InputStream is)