Skip to content

Commit

Permalink
Fix image missing in gallery (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubertm authored Mar 16, 2024
1 parent 38e7e24 commit 571b555
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private fun BoxScope.TopMenu(
},
onDismissClick = { viewModel.showSavePathDialog = false },
onPositiveClick = { savePath ->
viewModel.saveImage(savePath)
viewModel.saveImage(context, savePath)
viewModel.showSavePathDialog = false
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Matrix
import android.graphics.drawable.Drawable
import android.media.MediaScannerConnection
import android.net.Uri
import android.view.MotionEvent
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -126,18 +127,24 @@ class EditViewModel(
editManager.scaleToFit()
}

fun saveImage(savePath: Path) =
fun saveImage(context: Context, path: Path) {
viewModelScope.launch(Dispatchers.IO) {
isSavingImage = true
val combinedBitmap = getEditedImage()

savePath.outputStream().use { out ->
path.outputStream().use { out ->
combinedBitmap.asAndroidBitmap()
.compress(Bitmap.CompressFormat.PNG, 100, out)
}
MediaScannerConnection.scanFile(
context,
arrayOf(path.toString()),
arrayOf("image/*")
) { _, _ -> }
imageSaved = true
isSavingImage = false
}
}

fun shareImage(context: Context) =
viewModelScope.launch(Dispatchers.IO) {
Expand Down

0 comments on commit 571b555

Please sign in to comment.