Fix music widget album art scaling
This commit is contained in:
parent
d3358fa7b5
commit
eebffa333e
@ -287,8 +287,13 @@ class MusicRepositoryImpl(val context: Context) : MusicRepository, KoinComponent
|
||||
if (albumArt == null) {
|
||||
this@MusicRepositoryImpl.albumArt.value = null
|
||||
} else {
|
||||
val size = context.resources.getDimensionPixelSize(R.dimen.album_art_size)
|
||||
val scaledBitmap = albumArt.scale(size, size)
|
||||
val size = context.resources.getDimension(R.dimen.album_art_size)
|
||||
val (scaledW, scaledH) = if (albumArt.width > albumArt.height) {
|
||||
size * albumArt.width / albumArt.height to size
|
||||
} else {
|
||||
size to size * albumArt.height / albumArt.width
|
||||
}
|
||||
val scaledBitmap = albumArt.scale(scaledW.toInt(), scaledH.toInt())
|
||||
val file = File(context.cacheDir, "album_art")
|
||||
val outStream = file.outputStream()
|
||||
scaledBitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream)
|
||||
|
||||
@ -26,6 +26,7 @@ import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
@ -163,7 +164,8 @@ fun MusicWidget() {
|
||||
bitmap = it.asImageBitmap(),
|
||||
modifier = Modifier
|
||||
.fillMaxSize(),
|
||||
contentDescription = null
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
}
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user