feiyu02
9 天以前 85ef942e7195abeb71466b7159c3ee30161e1e54
src/main/kotlin/cn/flightfeather/supervision/common/utils/FileUtil.kt
@@ -122,6 +122,7 @@
                    fos.write(b, 0, a)
                    a = fis.read(b)
                }
            }
        }
@@ -145,30 +146,21 @@
    }
    /**
     * 按照固定宽度压缩图片至base64形式
     * 按照路径建立文件夹,并自动处理重复路径
     */
//    fun compressImage2(bytes: ByteArray): String {
//        val length = 1440//图片长边固定压缩为1440像素
//
//        val input = ByteArrayInputStream(bytes)
//        val srcImg = ImageIO.read(input)
//        var srcLong = 0
//        var srcShort = 0
//        if (srcImg.width <= srcImg.height) {
//            srcLong = srcImg.height
//            srcShort = srcImg.width
//
//        } else {
//
//        }
//        val scale = w.toFloat() / srcW
//        val h = (srcImg.height * scale).toInt()
//
//        val buffImg = BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB)
//        buffImg.graphics.drawImage(srcImg.getScaledInstance(w, h, Image.SCALE_SMOOTH), 0, 0, null)
//        val out = ByteArrayOutputStream()
//        ImageIO.write(buffImg, "PNG", out)
//
//        return SCHEME_PNG + Base64.getEncoder().encodeToString(out.toByteArray())
//    }
    fun mkDirs(basePath: String): File {
        var file = File(basePath)
        var i = 1
        while (file.exists() && i <= 100) {
            val path = "$basePath($i)"
            file = File(path)
            i++
        }
        if (file.exists()) {
            delAllFile(file.absolutePath)
        } else {
            file.mkdirs()
        }
        return file
    }
}