Kotlin 图片调整亮度

    /**
     * 图片亮度调整
     * @param image 图片
     * @param param 在当前亮度基础上添加或者减去亮度
     * @throws IOException
     */
    fun setImageLight(image: BufferedImage, param: Int): BufferedImage {
        for (i in 0 until image.width) {
            for (j in 0 until image.height) {
                var rgb = image.getRGB(i, j)
                val r = (rgb shr 16 and 0xff) + param
                val g = (rgb shr 8 and 0xff) + param
                val b = (rgb and 0xff) + param

                rgb = (clamp(255) and 0xff shl 24) or
                        (clamp(r) and 0xff shl 16) or
                        (clamp(g) and 0xff shl 8) or
                        (clamp(b) and 0xff)

                image.setRGB(i, j, rgb)
            }
        }
        return image
    }

你可能感兴趣的:(kotlin,开发语言,android)