All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.com.adamratzman.spotify.utils.IO.kt Maven / Gradle / Ivy

There is a newer version: 4.1.3
Show newest version
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2021; Original author: Adam Ratzman */
package com.adamratzman.spotify.utils

import java.io.ByteArrayOutputStream
import java.net.URL
import java.util.Base64
import javax.imageio.ImageIO

internal actual fun encodeBufferedImageToBase64String(image: BufferedImage): String {
    val bos = ByteArrayOutputStream()
    ImageIO.write(image, "jpg", bos)
    bos.close()
    return Base64.getEncoder().encodeToString(bos.toByteArray())
}

internal actual fun convertFileToBufferedImage(file: File): BufferedImage = ImageIO.read(file)

internal actual fun convertLocalImagePathToBufferedImage(path: String): BufferedImage = ImageIO.read(URL("file:///$path"))

internal actual fun convertUrlPathToBufferedImage(url: String): BufferedImage = ImageIO.read(URL(url))




© 2015 - 2024 Weber Informatics LLC | Privacy Policy