[+] Save to file

This commit is contained in:
2025-10-26 11:04:21 +08:00
parent 4ad07dc345
commit acbf4b8998
@@ -2,6 +2,7 @@ package aza.instant
import android.Manifest
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.Picture
import android.os.Bundle
import android.util.Log
@@ -109,13 +110,23 @@ fun FileListerScreen(modifier: Modifier = Modifier) {
coroutineScope.launch {
feedbackText = "Rendering..."
val imageDir = File("/storage/emulated/0/DCIM/CA_IMAGES/")
val latestImage = imageDir.listFiles()?.maxByOrNull { it.lastModified() }
val latestImage = imageDir.listFiles()
?.filter { !it.name.contains(".framed.") }
?.maxByOrNull { it.lastModified() }
if (latestImage != null) {
try {
val templateStream = context.resources.openRawResource(R.raw.postcard4)
val template = BufferedReader(InputStreamReader(templateStream)).readText()
val svg = genSvg(template, latestImage.absolutePath)
picture = renderSvgAndroid(svg)
picture = renderSvgAndroid(context, svg)
// Save picture to file
val file = File(latestImage.parent, "${latestImage.nameWithoutExtension}.framed.png")
file.createNewFile()
file.outputStream().use { outputStream ->
Bitmap.createBitmap(picture!!).compress(Bitmap.CompressFormat.PNG, 90, outputStream)
}
feedbackText = "Rendered ${latestImage.name}"
} catch (e: Exception) {
feedbackText = "Error rendering: ${e.message}"