Skip to content

Commit

Permalink
fix: webp动态图片判定问题修复
Browse files Browse the repository at this point in the history
  • Loading branch information
SherlockGougou committed Apr 11, 2023
1 parent 5bed7b6 commit d013852
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ allprojects {
```
dependencies {
// 添加本框架 BigImageViewPager https://github.com/SherlockGougou/BigImageViewPager
implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.2.2'
implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.2.3'
// 另外还需要依赖 glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
Expand Down
26 changes: 20 additions & 6 deletions library/src/main/java/cc/shinichi/library/tool/image/ImageUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ object ImageUtil {
options.inJustDecodeBounds = true
BitmapFactory.decodeFile(path, options)
var type = options.outMimeType
Log.d(TAG, "getImageTypeWithMime: type1 = $type")
Log.d(TAG, "getImageTypeWithMime: path = $path, type1 = $type")
// ”image/png”、”image/jpeg”、”image/gif”
type = if (TextUtils.isEmpty(type)) {
""
} else {
type.substring(6)
}
Log.d(TAG, "getImageTypeWithMime: type2 = $type")
Log.d(TAG, "getImageTypeWithMime: path = $path, type2 = $type")
return type
}

Expand Down Expand Up @@ -356,9 +356,23 @@ object ImageUtil {
}

fun isStaticImage(url: String, path: String): Boolean {
return (isJpegImageWithMime(url, path)// jpeg
|| isPngImageWithMime(url, path)// png
|| isBmpImageWithMime(url, path))// bmp
&& !isAnimImageWithMime(url, path)// 不是动图(不是webp动图、gif动图)
val isWebpImageWithMime = isWebpImageWithMime(url, path)
Log.d(TAG, "isStaticImage: isWebpImageWithMime = $isWebpImageWithMime")
if (isWebpImageWithMime) {
val animWebp = isAnimWebp(url, path)
Log.d(TAG, "isStaticImage: animWebp = $animWebp")
return !animWebp
}
val jpegImageWithMime = isJpegImageWithMime(url, path)
Log.d(TAG, "isStaticImage: jpegImageWithMime = $jpegImageWithMime")
val pngImageWithMime = isPngImageWithMime(url, path)
Log.d(TAG, "isStaticImage: pngImageWithMime = $pngImageWithMime")
val bmpImageWithMime = isBmpImageWithMime(url, path)
Log.d(TAG, "isStaticImage: bmpImageWithMime = $bmpImageWithMime")
val heifImageWithMime = isHeifImageWithMime(url, path)
Log.d(TAG, "isStaticImage: heifImageWithMime = $heifImageWithMime")
val animImageWithMime = isAnimImageWithMime(url, path)
Log.d(TAG, "isStaticImage: animImageWithMime = $animImageWithMime")
return (jpegImageWithMime || pngImageWithMime || bmpImageWithMime || heifImageWithMime) && !animImageWithMime
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ class ImagePreviewAdapter(private val activity: AppCompatActivity, imageList: Mu
val imagePath = cacheFile.absolutePath
val isStatic = isStaticImage(originPathUrl, imagePath)
if (isStatic) {
Log.d("instantiateItem", "动静判断: 静态图")
loadImageStatic(imagePath, imageStatic, imageAnim, progressBar)
} else {
Log.d("instantiateItem", "动静判断: 动态图")
loadImageAnim(originPathUrl, imagePath, imageStatic, imageAnim, progressBar)
}
} else {
Expand Down Expand Up @@ -275,6 +277,7 @@ class ImagePreviewAdapter(private val activity: AppCompatActivity, imageList: Mu
if (cacheFile != null && cacheFile.exists()) {
val isStatic = isStaticImage(originalUrl, cacheFile.absolutePath)
if (isStatic) {
Log.d("loadOrigin", "动静判断: 静态图")
val isHeifImageWithMime = isHeifImageWithMime(imageInfo.originUrl, cacheFile.absolutePath)
if (isHeifImageWithMime) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Expand Down Expand Up @@ -314,6 +317,7 @@ class ImagePreviewAdapter(private val activity: AppCompatActivity, imageList: Mu
imageStatic.setImage(origin, small)
}
} else {
Log.d("loadOrigin", "动静判断: 动态图")
imageStatic?.visibility = View.GONE
imageAnim?.visibility = View.VISIBLE
imageAnim?.let {
Expand Down Expand Up @@ -343,8 +347,10 @@ class ImagePreviewAdapter(private val activity: AppCompatActivity, imageList: Mu
val imagePath = resource.absolutePath
val isStatic = isStaticImage(imageUrl, imagePath)
if (isStatic) {
Log.d("loadSuccess", "动静判断: 静态图")
loadImageStatic(imagePath, imageStatic, imageAnim, progressBar)
} else {
Log.d("loadSuccess", "动静判断: 动态图")
loadImageAnim(imageUrl, imagePath, imageStatic, imageAnim, progressBar)
}
}
Expand Down
6 changes: 3 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "cc.shinichi.bigimageviewpager"
minSdkVersion 19
targetSdkVersion 33
versionCode 722
versionName "androidx-7.2.2"
versionCode 723
versionName "androidx-7.2.3"
}
buildTypes {
release {
Expand Down Expand Up @@ -55,6 +55,6 @@ dependencies {
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.11.0'
// library
// implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.2.2'
// implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.2.3'
implementation project(':library')
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ private void initData() {
i.setOriginUrl("https://yitaoyitao.oss-cn-qingdao.aliyuncs.com/app/img/temp/test/gif1.gif");
imageInfoList.add(i);

// 测试:
i = new ImageInfo();
i.setThumbnailUrl("https://switch-cdn.vgjump.com/Android_1681181317625_d2959134-f14b-4b7b-9f41-5c08fb72c4cb?imageView2/2/w/1080/h/0/format/webp/q/75|imageslim");
i.setOriginUrl("https://switch-cdn.vgjump.com/Android_1681181317625_d2959134-f14b-4b7b-9f41-5c08fb72c4cb");
imageInfoList.add(i);

// ==============================================================================================================
// 一、最简单的调用:
Expand Down

0 comments on commit d013852

Please sign in to comment.