diff app/src/main/java/com/bartsent/simpleresizer/lib/getScaledInstance.kt @ 15:20da616dcda0

Add preferences.
author David Barts <n5jrn@me.com>
date Thu, 18 Feb 2021 22:12:19 -0800
parents b1605be35bcc
children 86740f593b6c
line wrap: on
line diff
--- a/app/src/main/java/com/bartsent/simpleresizer/lib/getScaledInstance.kt	Thu Feb 18 15:19:07 2021 -0800
+++ b/app/src/main/java/com/bartsent/simpleresizer/lib/getScaledInstance.kt	Thu Feb 18 22:12:19 2021 -0800
@@ -1,21 +1,23 @@
 package com.bartsent.simpleresizer.lib
 
 import android.graphics.Bitmap
-import android.graphics.Canvas
-import android.graphics.Color
-import android.graphics.Matrix
-import kotlin.math.ceil
-import kotlin.math.floor
 
 private data class IndexWeight(var index: Int, var weight: Double)
 
+/**
+ * A quality scaler, rather simpler than Image.getScaledInstance in that it has only
+ * one (slow, high-quality) option.
+ * @param       newWidth        Width of new bitmap
+ * @param       newHeight       Height of new bitmap
+ * @return                      New bitmap
+ */
 fun Bitmap.getScaledInstance(newWidth: Int, newHeight: Int): Bitmap {
     if (newWidth <= 0)
         throw IllegalArgumentException("invalid width: $newWidth")
     if (newHeight <= 0)
         throw IllegalArgumentException("invalid height: $newHeight")
     if (width == newWidth && height == newHeight)
-        return Bitmap.createBitmap(this)
+        return this
     return if (width != newWidth) {
         Resizer.fromBitmap(this).horizontal(newWidth).let {
             if (height == newHeight) it else it.vertical(newHeight)