mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-28 12:30:12 +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) {
|
||||
download.outputFile?.let { File(it) }?.takeIf { it.exists() }?.let {
|
||||
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)
|
||||
|
||||
Bitmap.createScaledBitmap(
|
||||
|
@ -43,16 +43,14 @@ object PreviewUtils {
|
||||
}.getFrameAtTime(0, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)
|
||||
}
|
||||
|
||||
fun createPreviewFromFile(file: File, scaleFactor: Float): Bitmap? {
|
||||
fun createPreviewFromFile(file: File): Bitmap? {
|
||||
return if (FileType.fromFile(file).isVideo) {
|
||||
MediaMetadataRetriever().apply {
|
||||
setDataSource(file.absolutePath)
|
||||
}.getFrameAtTime(0, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)?.let {
|
||||
resizeBitmap(it, (it.width * scaleFactor).toInt(), (it.height * scaleFactor).toInt())
|
||||
}
|
||||
}.getFrameAtTime(0, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)
|
||||
} else {
|
||||
BitmapFactory.decodeFile(file.absolutePath, BitmapFactory.Options().apply {
|
||||
inSampleSize = (1 / scaleFactor).roundToInt()
|
||||
inSampleSize = 1
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user