Skip to content

Commit

Permalink
🐛 Avoid jagged graphics by using native rounded corners (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang authored Nov 24, 2023
1 parent 4296818 commit c50b77d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun ClipeveryApp(dependencies: Dependencies) {
MaterialTheme {
Column(Modifier.fillMaxWidth()
.clip(RoundedCornerShape(10.dp))
.background(Color.White),
.background(Color(238, 238, 238)),
horizontalAlignment = Alignment.CenterHorizontally) {
ClipeveryCommon(dependencies)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.clipevery.utils
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.toComposeImageBitmap
import com.clipevery.net.ClipServer
import com.clipevery.platform.currentPlatform
import com.google.zxing.BarcodeFormat
import com.google.zxing.qrcode.QRCodeWriter
import java.awt.Color
Expand All @@ -18,11 +19,21 @@ class DesktopQRCodeGenerator(private val clipServer: ClipServer) : QRCodeGenerat
}

override fun generateQRCode(width: Int, height: Int): ImageBitmap {
val imageWidth: Int
val imageHeight: Int
if (currentPlatform().isWindows()) {
imageWidth = width * 3 / 4
imageHeight = height * 3 / 4
} else{
imageWidth = width
imageHeight = height
}

val writer = QRCodeWriter()
val bitMatrix = writer.encode(bindInfo(), BarcodeFormat.QR_CODE, width, height)
val image = BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)
for (x in 0 until width) {
for (y in 0 until height) {
val bitMatrix = writer.encode(bindInfo(), BarcodeFormat.QR_CODE, imageWidth, imageHeight)
val image = BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB)
for (x in 0 until imageWidth) {
for (y in 0 until imageHeight) {
image.setRGB(x, y, if (bitMatrix.get(x, y)) Color.BLACK.rgb else Color.WHITE.rgb)
}
}
Expand Down

0 comments on commit c50b77d

Please sign in to comment.