Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.BitmapFactory; import java.io.InputStream; public class Main { /** * Determines if the file contains a valid image. * * @param pathName A file path. * @return {@code true} if the stream contains a valid image; {@code false} if not. */ public static boolean hasImageContent(String pathName) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(pathName, options); return options.outMimeType != null; } /** * Determines if the stream contains a valid image. * * @param inputStream An input stream. * @return {@code true} if the stream contains a valid image; {@code false} if not. */ public static boolean hasImageContent(InputStream inputStream) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(inputStream, null, options); return options.outMimeType != null; } }