package com.linkwechat.common.utils;

import javax.activation.MimetypesFileTypeMap;
import java.io.File;

/**
 * @description:
 * @author: HaoN
 * @create: 2021-06-08 15:27
 **/
public class ImageCheckUtils {
    private static MimetypesFileTypeMap mtftp;

    static {
        mtftp = new MimetypesFileTypeMap();
        /* 不添加下面的类型会造成误判 详见：http://stackoverflow.com/questions/4855627/java-mimetypesfiletypemap-always-returning-application-octet-stream-on-android-e*/
        mtftp.addMimeTypes("image png tif jpg jpeg bmp");
    }


    public  static boolean isImage(File file){
        String mimetype= mtftp.getContentType(file);
        String type = mimetype.split("/")[0];
        return type.equals("image");
    }

}
