From 64f4bf9466b0ca52c0aacccdfa20b0479a120b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=80=E6=BC=93=E4=B8=A8Sevtinge?= <89193494+Sevtinge@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:01:54 +0800 Subject: [PATCH] Fix the preview uses stretching instead of tiling (#3) --- .../top/yukonga/mediaControlBlur/MainHook.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/top/yukonga/mediaControlBlur/MainHook.kt b/app/src/main/kotlin/top/yukonga/mediaControlBlur/MainHook.kt index 658ad54..7dccc68 100644 --- a/app/src/main/kotlin/top/yukonga/mediaControlBlur/MainHook.kt +++ b/app/src/main/kotlin/top/yukonga/mediaControlBlur/MainHook.kt @@ -145,19 +145,24 @@ class MainHook : IXposedHookLoadPackage { val canvas = Canvas(artworkBitmap) artworkLayer.setBounds(0, 0, artworkLayer.intrinsicWidth, artworkLayer.intrinsicHeight) artworkLayer.draw(canvas) - val resizedBitmap = Bitmap.createScaledBitmap(artworkBitmap, 300, 300, true) + val minDimen = Math.min(artworkBitmap.width, artworkBitmap.height) + val left = (artworkBitmap.width - minDimen) / 2 + val top = (artworkBitmap.height - minDimen) / 2 + val rect = Rect(left, top, left + minDimen, top + minDimen) + val croppedBitmap = Bitmap.createBitmap(minDimen, minDimen, Bitmap.Config.ARGB_8888) + val canvasCropped = Canvas(croppedBitmap) + canvasCropped.drawBitmap(artworkBitmap, rect, Rect(0, 0, minDimen, minDimen), null) val radius = 45f - val newBitmap = Bitmap.createBitmap(resizedBitmap.width, resizedBitmap.height, Bitmap.Config.ARGB_8888) + val newBitmap = Bitmap.createBitmap(croppedBitmap.width, croppedBitmap.height, Bitmap.Config.ARGB_8888) val canvas1 = Canvas(newBitmap) val paint = Paint() - val rect = Rect(0, 0, resizedBitmap.width, resizedBitmap.height) - val rectF = RectF(rect) + val rectF = RectF(0f, 0f, croppedBitmap.width.toFloat(), croppedBitmap.height.toFloat()) paint.isAntiAlias = true canvas1.drawARGB(0, 0, 0, 0) paint.color = Color.BLACK canvas1.drawRoundRect(rectF, radius, radius, paint) paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) - canvas1.drawBitmap(resizedBitmap, rect, rect, paint) + canvas1.drawBitmap(croppedBitmap, 0f, 0f, paint) albumView?.setImageDrawable(BitmapDrawable(context.resources, newBitmap)) (appIcon?.parent as ViewGroup?)?.removeView(appIcon)