mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-29 13:00:17 +02:00
fix: preview scale factor
This commit is contained in:
parent
4619a4fdc0
commit
313cb7cf1b
@ -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(
|
||||||
|
@ -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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user