Yokan / rebuild
Course 1 8624561

ImageDecoder.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/image/ImageDecoder.kt

implementation17 lines
1package eu.friedcutlet.yokan.ui.image23import androidx.compose.ui.graphics.ImageBitmap4import eu.friedcutlet.yokan.services.files.createPlatformLocalFileService5import org.jetbrains.compose.resources.decodeToImageBitmap67/**8 * Decode the image at [path] into an [ImageBitmap]. Used by the theme system to9 * derive a Material seed color from a user-chosen image via MaterialKolor's10 * `themeColor(image: ImageBitmap, …)` extension.11 *12 * Bytes come from the platform [eu.friedcutlet.yokan.services.files.LocalFileService], so13 * picker results that are not plain paths (Android `content://`, iOS security-scoped URLs,14 * browser-selected files) decode too. Returns null when the file is missing or undecodable.15 */16internal fun decodeImageBitmap(path: String): ImageBitmap? =17    runCatching { createPlatformLocalFileService().readBytes(path).decodeToImageBitmap() }.getOrNull()18

Search chapters, reference and source filenames.