diff --git a/kotlin-app/src/main/kotlin/io/github/simonscholz/service/RenderImageService.kt b/kotlin-app/src/main/kotlin/io/github/simonscholz/service/RenderImageService.kt index 74794b8..69b94c0 100644 --- a/kotlin-app/src/main/kotlin/io/github/simonscholz/service/RenderImageService.kt +++ b/kotlin-app/src/main/kotlin/io/github/simonscholz/service/RenderImageService.kt @@ -7,6 +7,7 @@ import io.github.simonscholz.qrcode.QrPositionalSquaresConfig import io.github.simonscholz.ui.ImageUI import java.awt.Color import java.awt.Component +import java.awt.Image import java.awt.image.BufferedImage import java.io.File import javax.imageio.ImageIO @@ -38,8 +39,13 @@ object RenderImageService { if (qrCodeConfigViewModel.logo.value.isNotBlank() && File(qrCodeConfigViewModel.logo.value).exists()) { runCatching { ImageIO.read(File(qrCodeConfigViewModel.logo.value)).let { + + val logoSize = (qrCodeConfigViewModel.size.value * qrCodeConfigViewModel.logoRelativeSize.value).toInt() + + val scaledLogo = it.getScaledInstance(logoSize, logoSize, Image.SCALE_SMOOTH) + builder.qrLogoConfig( - logo = it, + logo = scaledLogo, relativeSize = qrCodeConfigViewModel.logoRelativeSize.value, bgColor = qrCodeConfigViewModel.logoBackgroundColor.value, ) diff --git a/qr-code/src/main/kotlin/io/github/simonscholz/qrcode/QrCodeConfig.kt b/qr-code/src/main/kotlin/io/github/simonscholz/qrcode/QrCodeConfig.kt index aee6670..ed8637f 100644 --- a/qr-code/src/main/kotlin/io/github/simonscholz/qrcode/QrCodeConfig.kt +++ b/qr-code/src/main/kotlin/io/github/simonscholz/qrcode/QrCodeConfig.kt @@ -1,7 +1,7 @@ package io.github.simonscholz.qrcode import java.awt.Color -import java.awt.image.BufferedImage +import java.awt.Image const val DEFAULT_IMG_SIZE = 300 @@ -37,7 +37,7 @@ class QrCodeConfig @JvmOverloads constructor( fun qrCodeSize(qrCodeSize: Int) = apply { this.qrCodeSize = qrCodeSize } - @JvmOverloads fun qrLogoConfig(logo: BufferedImage, relativeSize: Double = .2, bgColor: Color? = null) = apply { this.qrLogoConfig = QrLogoConfig(logo, relativeSize, bgColor) } + @JvmOverloads fun qrLogoConfig(logo: Image, relativeSize: Double = .2, bgColor: Color? = null) = apply { this.qrLogoConfig = QrLogoConfig(logo, relativeSize, bgColor) } @JvmOverloads fun qrCodeColorConfig(bgColor: Color = Color.WHITE, fillColor: Color = Color.BLACK) = apply { this.qrCodeColorConfig = QrCodeColorConfig(bgColor, fillColor) } @@ -64,7 +64,7 @@ class QrCodeConfig @JvmOverloads constructor( * @param bgColor - specify the background color of the logo, defaults to null */ class QrLogoConfig @JvmOverloads constructor( - val logo: BufferedImage, + val logo: Image, val relativeSize: Double = .2, val bgColor: Color? = null, ) { diff --git a/qr-code/src/main/kotlin/io/github/simonscholz/qrcode/internal/logo/LogoGraphics.kt b/qr-code/src/main/kotlin/io/github/simonscholz/qrcode/internal/logo/LogoGraphics.kt index 183a400..2613c8f 100644 --- a/qr-code/src/main/kotlin/io/github/simonscholz/qrcode/internal/logo/LogoGraphics.kt +++ b/qr-code/src/main/kotlin/io/github/simonscholz/qrcode/internal/logo/LogoGraphics.kt @@ -2,6 +2,7 @@ package io.github.simonscholz.qrcode.internal.logo import java.awt.Color import java.awt.Graphics2D +import java.awt.Image import java.awt.geom.Area import java.awt.geom.Ellipse2D import java.awt.image.BufferedImage @@ -9,7 +10,7 @@ import kotlin.math.floor internal object LogoGraphics { - fun drawLogo(graphics: Graphics2D, size: Int, logoImage: BufferedImage, relativeLogoSize: Double, logoBackgroundColor: Color?) { + fun drawLogo(graphics: Graphics2D, size: Int, logoImage: Image, relativeLogoSize: Double, logoBackgroundColor: Color?) { val logoSize: Int = floor(size * relativeLogoSize).toInt() val cx = size / 2 - logoSize / 2 val cy = size / 2 - logoSize / 2