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

commonMain.org.jetbrains.compose.resources.ImageDecoders.kt Maven / Gradle / Ivy

package org.jetbrains.compose.resources

import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Density
import org.jetbrains.compose.resources.vector.toImageVector

/**
 * Decodes a byte array of a Bitmap to an ImageBitmap. Supports JPEG, PNG, BMP, WEBP
 *
 * Different platforms can support additional formats.
 *
 * @return The converted ImageBitmap.
 */
@ExperimentalResourceApi
fun ByteArray.decodeToImageBitmap(): ImageBitmap {
    val dumbDensity = 0 //any equal source and target density disable scaling here
    return this.toImageBitmap(dumbDensity, dumbDensity)
}

/**
 * Decodes a byte array of a vector XML file to an ImageVector.
 *
 * @param density density to apply during converting the source units to the [ImageVector] units.
 *
 * @return The converted ImageVector.
 */
@ExperimentalResourceApi
fun ByteArray.decodeToImageVector(density: Density): ImageVector {
    return this.toXmlElement().toImageVector(density)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy