ios显示不了的图片的原因是ios不能显示webP 格式的图片
显示不了的一般为 android 下载的webP 格式,但是后缀为 jpg 或者png 的图片文件
解决方案有几种
一通过文件头文件 判断图片类型是否为 webP 如果是则不给选择。
二转换文件格式 将上传的文件格式统一转化为jpg。
三 ios端下载时去转换
/**
* 转换成JPG格式图片 并将原照片删除
*
* @param pngFilePath png或者bmp照片
* @param jpgFilePath jpg照片
*/
private static void convertToJpg(String pngFilePath, String jpgFilePath) {
Bitmap bitmap = BitmapFactory.decodeFile(pngFilePath);
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(jpgFilePath));
if (bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos)) {
bos.flush();
}
bos.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
bitmap.recycle();
bitmap = null;
}
//删除非JPG照片
if (!pngFilePath.equals(jpgFilePath)) {
File oldImg = new File(pngFilePath);
oldImg.delete();
}
}