优化
This commit is contained in:
@@ -89,7 +89,7 @@ object BookController {
|
|||||||
this.bookUrl = bookUrl
|
this.bookUrl = bookUrl
|
||||||
val bitmap = runBlocking {
|
val bitmap = runBlocking {
|
||||||
ImageProvider.cacheImage(book, src, bookSource)
|
ImageProvider.cacheImage(book, src, bookSource)
|
||||||
ImageProvider.getImage(book, src, width, width)
|
ImageProvider.getImage(book, src, width)
|
||||||
}
|
}
|
||||||
return returnData.setData(bitmap)
|
return returnData.setData(bitmap)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,4 +80,25 @@ object ImageProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getImage(
|
||||||
|
book: Book,
|
||||||
|
src: String,
|
||||||
|
width: Int
|
||||||
|
): Bitmap {
|
||||||
|
val vFile = BookHelp.getImage(book, src)
|
||||||
|
@Suppress("BlockingMethodInNonBlockingContext")
|
||||||
|
return try {
|
||||||
|
BitmapUtils.decodeBitmap(vFile.absolutePath, width)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Coroutine.async {
|
||||||
|
putDebug("${vFile.absolutePath} 解码失败\n$e", e)
|
||||||
|
if (FileUtils.readText(vFile.absolutePath).isXml()) {
|
||||||
|
putDebug("${vFile.absolutePath}为xml,自动删除")
|
||||||
|
vFile.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
errorBitmap
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,22 @@ object BitmapUtils {
|
|||||||
return BitmapFactory.decodeFile(path, op)
|
return BitmapFactory.decodeFile(path, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun decodeBitmap(path: String, width: Int): Bitmap {
|
||||||
|
val op = BitmapFactory.Options()
|
||||||
|
// inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight;
|
||||||
|
op.inJustDecodeBounds = true
|
||||||
|
BitmapFactory.decodeFile(path, op)
|
||||||
|
//获取比例大小
|
||||||
|
val wRatio = ceil((op.outWidth / width).toDouble()).toInt()
|
||||||
|
//如果超出指定大小,则缩小相应的比例
|
||||||
|
if (wRatio > 1) {
|
||||||
|
op.inSampleSize = wRatio
|
||||||
|
}
|
||||||
|
op.inJustDecodeBounds = false
|
||||||
|
return BitmapFactory.decodeFile(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
/** 从path中获取Bitmap图片
|
/** 从path中获取Bitmap图片
|
||||||
* @param path 图片路径
|
* @param path 图片路径
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
Reference in New Issue
Block a user