给定一个文件路径,知道该文件是否是 Java(Android) 中的(任何类型的)图像的最简单方法是什么?谢谢
最佳答案
public static boolean isImage(File file) {
if (file == null || !file.exists()) {
return false;
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getPath(), options);
return options.outWidth != -1 && options.outHeight != -1;
}
关于java - 在 Java/Android 中知道一个文件是否是图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9244710/