From 80c56322f626109e8331191963fa941a424c73d5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 23 May 2022 11:10:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/utils/ViewExtensions.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt index 271c5322b..4a7f5ab90 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -126,13 +126,17 @@ fun View.visible(visible: Boolean) { } } -fun View.screenshot(): Bitmap { - val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) - val c = Canvas(screenshot) - c.translate(-scrollX.toFloat(), -scrollY.toFloat()) - this.draw(c) - c.setBitmap(null) - return screenshot +fun View.screenshot(): Bitmap? { + return if (width > 0 && height > 0) { + val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) + val c = Canvas(screenshot) + c.translate(-scrollX.toFloat(), -scrollY.toFloat()) + this.draw(c) + c.setBitmap(null) + screenshot + } else { + null + } } fun SeekBar.progressAdd(int: Int) {