判斷一個文件是否是圖片文件的方法,采用BitmapFactory去decode然后根據返回的Options參數來確定:
public static boolean isImageFile(String filePath) {
Options options = new Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
if (options.outWidth == -1) {
return false;
}
return true;
}