首页 > 解决方案 > Android位图压缩webp到jpg不改变mime类型

问题描述

当我使用 compress(CompressFormat format, int quality, OutputStream stream) 函数将 webp 压缩为 jpg 时,它的后缀更改为 .jpg。

但它的 mimeType 没有改变,仍然是“image/webp”。

所以存在不支持webp的手机无法预览的问题。谁能给我答案?

webpBitmap.compress(Bitmap.CompressFormat.JPEG, 45, fos)

//get mime type from bitmap file
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
BitmapFactory.decodeFile(file.absolutePath, options)
return options.outMimeType

// it return "image/webp" not "image/jpg"

问题是为什么bitmap.compress不会改变文件 mime 类型

标签: androidbitmapcompressionjpegwebp

解决方案


推荐阅读