fix: preview scale factor

This commit is contained in:
rhunk 2023-06-26 03:29:45 +02:00
parent 4619a4fdc0
commit 313cb7cf1b
2 changed files with 4 additions and 6 deletions

View File

@ -66,7 +66,7 @@ class DownloadListAdapter(
private fun handlePreview(download: PendingDownload, holder: ViewHolder) { private fun handlePreview(download: PendingDownload, holder: ViewHolder) {
download.outputFile?.let { File(it) }?.takeIf { it.exists() }?.let { download.outputFile?.let { File(it) }?.takeIf { it.exists() }?.let {
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
val previewBitmap = PreviewUtils.createPreviewFromFile(it, 1F)?.let { preview -> val previewBitmap = PreviewUtils.createPreviewFromFile(it)?.let { preview ->
val offsetY = (preview.height / 2 - holder.viewHeight / 2).coerceAtLeast(0) val offsetY = (preview.height / 2 - holder.viewHeight / 2).coerceAtLeast(0)
Bitmap.createScaledBitmap( Bitmap.createScaledBitmap(

View File

@ -43,16 +43,14 @@ object PreviewUtils {
}.getFrameAtTime(0, MediaMetadataRetriever.OPTION_CLOSEST_SYNC) }.getFrameAtTime(0, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)
} }
fun createPreviewFromFile(file: File, scaleFactor: Float): Bitmap? { fun createPreviewFromFile(file: File): Bitmap? {
return if (FileType.fromFile(file).isVideo) { return if (FileType.fromFile(file).isVideo) {
MediaMetadataRetriever().apply { MediaMetadataRetriever().apply {
setDataSource(file.absolutePath) setDataSource(file.absolutePath)
}.getFrameAtTime(0, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)?.let { }.getFrameAtTime(0, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)
resizeBitmap(it, (it.width * scaleFactor).toInt(), (it.height * scaleFactor).toInt())
}
} else { } else {
BitmapFactory.decodeFile(file.absolutePath, BitmapFactory.Options().apply { BitmapFactory.decodeFile(file.absolutePath, BitmapFactory.Options().apply {
inSampleSize = (1 / scaleFactor).roundToInt() inSampleSize = 1
}) })
} }
} }