Add ImageWrite to write images, move to images namespace
This commit is contained in:
@@ -38,7 +38,7 @@ import app.klottr.ui.WriteDocContent
|
||||
import app.klottr.util.SettingsStore
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import app.klottr.images.loadImageBitmap
|
||||
import app.klottr.net.ImageHandle
|
||||
import app.klottr.images.ImageHandle
|
||||
import app.klottr.images.rememberVisualMediaPicker
|
||||
import kotlin.time.Clock
|
||||
import kotlin.time.ExperimentalTime
|
||||
|
||||
@@ -2,8 +2,6 @@ package app.klottr.images
|
||||
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import org.jetbrains.compose.resources.decodeToImageBitmap
|
||||
import app.klottr.net.ImageHandle
|
||||
import app.klottr.net.ImageReader
|
||||
|
||||
/**
|
||||
* Platform-independent: reads image bytes via ImageReader (expect/actual),
|
||||
|
||||
46
shared/src/commonMain/kotlin/app/klottr/images/ImageWrite.kt
Normal file
46
shared/src/commonMain/kotlin/app/klottr/images/ImageWrite.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
package app.klottr.images
|
||||
|
||||
data class ImageSaveResult(
|
||||
val absolutePath: String,
|
||||
val mime: String,
|
||||
val filename: String
|
||||
)
|
||||
|
||||
/**
|
||||
* Persist image bytes to a private, app-scoped directory.
|
||||
* Must be init():ed on Android with ApplicationContext, no-op on iOS (matches ImageReader).
|
||||
*/
|
||||
expect object ImageWriter {
|
||||
/** Android: pass ApplicationContext. iOS: no-op. */
|
||||
fun init(platformContext: Any?)
|
||||
|
||||
/**
|
||||
* Save raw [bytes] with [mime] to a platform-private subdirectory [subdir].
|
||||
* The concrete platform chooses the parent root (e.g. filesDir on Android, Application Support on iOS).
|
||||
* [baseName] should be a filename stem without extension; the appropriate extension is derived from [mime].
|
||||
*/
|
||||
suspend fun saveImage(
|
||||
bytes: ByteArray,
|
||||
mime: String,
|
||||
subdir: String,
|
||||
baseName: String
|
||||
): ImageSaveResult?
|
||||
|
||||
/**
|
||||
* Convenience overload for your existing ImageReader result.
|
||||
*/
|
||||
suspend fun save(
|
||||
read: ImageReadResult,
|
||||
subdir: String,
|
||||
baseName: String
|
||||
): ImageSaveResult?
|
||||
}
|
||||
|
||||
/** Shared helper: translate mime -> file extension. */
|
||||
internal fun extFromMime(mime: String): String = when {
|
||||
mime.equals("image/jpeg", true) || mime.equals("image/jpg", true) -> ".jpg"
|
||||
mime.equals("image/png", true) -> ".png"
|
||||
mime.equals("image/webp", true) -> ".webp"
|
||||
mime.equals("image/gif", true) -> ".gif"
|
||||
else -> ".img"
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package app.klottr.images
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import app.klottr.net.ImageHandle
|
||||
|
||||
/**
|
||||
* Simple, callback-based image picker.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package app.klottr.net
|
||||
package app.klottr.images
|
||||
|
||||
/**
|
||||
* Plattformoberoende inläsning av bildbytes inför uppladdning.
|
||||
Reference in New Issue
Block a user