Merge pull request #1787 from Xwite/master

fix:return -1 when decode failed
pull/1788/head
kunfei 2 years ago committed by GitHub
commit 84d40c2638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt

@ -46,8 +46,8 @@ object ImageProvider {
) { ) {
if (evicted) { if (evicted) {
oldBitmap.recycle() oldBitmap.recycle()
putDebug("自动回收Bitmap path: $key") putDebug("ImageProvider: trigger bitmap recycle. URI: $key")
putDebug("bitmapLruCache : ${size()} / ${maxSize()}") putDebug("ImageProvider : cacheUsage ${size()}bytes / ${maxSize()}bytes")
} }
} }
} }
@ -90,7 +90,7 @@ object ImageProvider {
// inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight; // inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight;
op.inJustDecodeBounds = true op.inJustDecodeBounds = true
BitmapFactory.decodeFile(file.absolutePath, op) BitmapFactory.decodeFile(file.absolutePath, op)
if (op.outWidth == 0 && op.outHeight == 0) { if (op.outWidth < 1 && op.outHeight < 1) {
return Size(errorBitmap.width, errorBitmap.height) return Size(errorBitmap.width, errorBitmap.height)
} }
return Size(op.outWidth, op.outHeight) return Size(op.outWidth, op.outHeight)
@ -116,9 +116,9 @@ object ImageProvider {
bitmap bitmap
}.onFailure { }.onFailure {
Coroutine.async { Coroutine.async {
putDebug("${vFile.absolutePath} 解码失败\n$it", it) putDebug("ImageProvider: decode bitmap failed. path: ${vFile.absolutePath}\n$it", it)
if (FileUtils.readText(vFile.absolutePath).isXml()) { if (FileUtils.readText(vFile.absolutePath).isXml()) {
putDebug("${vFile.absolutePath}为xml,自动删除") putDebug("ImageProvider: delete xml file. path: ${vFile.absolutePath}")
vFile.delete() vFile.delete()
} }
} }

Loading…
Cancel
Save