Java BufferedImage Read isImage(File file)

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

Description

is Image

License

Open Source License

Declaration

public static boolean isImage(File file) 

Method Source Code

//package com.java2s;
/*//from   w  w  w .  j a v a 2 s .c  o m
 * $RCSfile: ImageHepler,v $$
 * $Revision: 1.0  $
 * $Date: 2011  $
 *
 * Copyright (C) 2011 GyTech, Inc. All rights reserved.
 *
 * This software is the proprietary information of GyTech, Inc.
 * Use is subject to license terms.
 */

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

public class Main {
    public static boolean isImage(File file) {
        boolean flag = false;
        try {
            BufferedImage image = ImageIO.read(file);
            if (image == null) {
                return flag;
            }

            int width = image.getWidth();
            int heigth = image.getHeight();
            if (width == 0 || heigth == 0) {
                return flag;
            }
            flag = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return flag;

    }
}

Related

  1. isImage(File file)
  2. isImage(File imageFile)