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 8c6d2e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
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 {
return this.toImageBitmap(0, 0)
}

/**
* 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 8c6d2e9

Please sign in to comment.