Small updates

This commit is contained in:
Him188 2019-10-05 13:42:00 +08:00
parent 2d825992bb
commit 8e97b47a8c

View File

@ -1,8 +1,8 @@
package net.mamoe.mirai.utils package net.mamoe.mirai.utils
import java.awt.* import java.awt.Image
import java.awt.image.BufferedImage import java.awt.image.BufferedImage
import java.util.ArrayList import java.util.*
import java.util.concurrent.Callable import java.util.concurrent.Callable
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
@ -22,7 +22,7 @@ class CharImageConverter @JvmOverloads constructor(
/* /*
* resize Image * resize Image
* */ * */
val newHeight = (this.image!!.getHeight() * (width.toDouble() / this.image!!.getWidth())).toInt() val newHeight = (this.image!!.height * (width.toDouble() / this.image!!.width)).toInt()
val tmp = image!!.getScaledInstance(width, newHeight, Image.SCALE_SMOOTH) val tmp = image!!.getScaledInstance(width, newHeight, Image.SCALE_SMOOTH)
val dimg = BufferedImage(width, newHeight, BufferedImage.TYPE_INT_ARGB) val dimg = BufferedImage(width, newHeight, BufferedImage.TYPE_INT_ARGB)
val g2d = dimg.createGraphics() val g2d = dimg.createGraphics()
@ -33,14 +33,14 @@ class CharImageConverter @JvmOverloads constructor(
val builder = StringBuilder() val builder = StringBuilder()
val lines = ArrayList<StringBuilder>(this.image!!.getHeight()) val lines = ArrayList<StringBuilder>(this.image!!.height)
var minXPos = this.width var minXPos = this.width
var maxXPos = 0 var maxXPos = 0
for (y in 0 until image!!.getHeight()) { for (y in 0 until image!!.height) {
val builderLine = StringBuilder() val builderLine = StringBuilder()
for (x in 0 until image!!.getWidth()) { for (x in 0 until image!!.width) {
val gray = gray(image!!.getRGB(x, y)) val gray = gray(image!!.getRGB(x, y))
if (grayCompare(gray, background)) { if (grayCompare(gray, background)) {
builderLine.append(" ") builderLine.append(" ")