美文网首页
Android-精确获取图片mimeType

Android-精确获取图片mimeType

作者: XII01 | 来源:发表于2020-07-06 09:49 被阅读0次
/**
  * 获取图片类格式
  *
  * @param filePath
  * ”image/png”、”image/jpeg”、”image/gif”
  * @return
  */
 public static String getLocaPathMimeType(String filePath) {
     try {
         BitmapFactory.Options options = new BitmapFactory.Options();
         options.inJustDecodeBounds = true;
         BitmapFactory.decodeFile(filePath, options);
         return options.outMimeType.replace("image/", ".");
     } catch (Exception e) {
         return JPG;
     }
 }

上面是针对本地文件,针对于网络图片的办法就是,将图片保存到本地,监听图片下载完成后,在传入上面方法获取mimeType,在根据需求展示

相关文章

网友评论

      本文标题:Android-精确获取图片mimeType

      本文链接:https://www.haomeiwen.com/subject/bkxwqktx.html