/**
* 判断图片base64字符串的文件格式
*
* @param base64ImgData
* @return
*/
public static String checkImageBase64Format(String base64ImgData) {
byte[] b = Base64.getDecoder().decode(base64ImgData);
String type = "";
if (0x8950 == ((b[0] & 0xff) << 8 | (b[1] & 0xff))) {
type = "png";
} else if (0xFFD8 == ((b[0] & 0xff) << 8 | (b[1] & 0xff))) {
type = "jpg";
}
return type;
}
判断图片base64字符串的文件格式
于 2021-08-06 14:19:44 首次发布