Skip to content

Commit

Permalink
[resources] Add a byte array to ImageBitmap converter
Browse files Browse the repository at this point in the history
  • Loading branch information
terrakok committed Jul 23, 2024
1 parent fbd4c42 commit 5332ee1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.jetbrains.compose.resources

import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Density

/**
* Decodes a byte array of an SVG file to a compose Painter.
*
* @param density density to apply during converting the source units to the [Painter] units.
*
* @return The converted Painter.
*/
@ExperimentalResourceApi
Expand Down

0 comments on commit 5332ee1

Please sign in to comment.