mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-05 12:54:35 +00:00
Calculate video output size taking into account portrait mode (#5068)
This commit is contained in:
committed by
GitHub
parent
7c982a30cb
commit
33aa7a914f
+1
-1
@@ -64,7 +64,7 @@ fun BitmapFactory.Options.calculateInSampleSize(desiredWidth: Int, desiredHeight
|
|||||||
* Decodes the [inputStream] into a [Bitmap] and applies the needed rotation based on [orientation].
|
* Decodes the [inputStream] into a [Bitmap] and applies the needed rotation based on [orientation].
|
||||||
* This orientation value must be one of `ExifInterface.ORIENTATION_*` constants.
|
* This orientation value must be one of `ExifInterface.ORIENTATION_*` constants.
|
||||||
*/
|
*/
|
||||||
fun Bitmap.rotateToMetadataOrientation(orientation: Int): Bitmap {
|
fun Bitmap.rotateToExifMetadataOrientation(orientation: Int): Bitmap {
|
||||||
val matrix = Matrix()
|
val matrix = Matrix()
|
||||||
when (orientation) {
|
when (orientation) {
|
||||||
ExifInterface.ORIENTATION_ROTATE_270 -> matrix.postRotate(270f)
|
ExifInterface.ORIENTATION_ROTATE_270 -> matrix.postRotate(270f)
|
||||||
|
|||||||
+2
-2
@@ -13,7 +13,7 @@ import android.graphics.BitmapFactory
|
|||||||
import androidx.exifinterface.media.ExifInterface
|
import androidx.exifinterface.media.ExifInterface
|
||||||
import io.element.android.libraries.androidutils.bitmap.calculateInSampleSize
|
import io.element.android.libraries.androidutils.bitmap.calculateInSampleSize
|
||||||
import io.element.android.libraries.androidutils.bitmap.resizeToMax
|
import io.element.android.libraries.androidutils.bitmap.resizeToMax
|
||||||
import io.element.android.libraries.androidutils.bitmap.rotateToMetadataOrientation
|
import io.element.android.libraries.androidutils.bitmap.rotateToExifMetadataOrientation
|
||||||
import io.element.android.libraries.androidutils.file.createTmpFile
|
import io.element.android.libraries.androidutils.file.createTmpFile
|
||||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||||
import io.element.android.libraries.core.extensions.runCatchingExceptions
|
import io.element.android.libraries.core.extensions.runCatchingExceptions
|
||||||
@@ -78,7 +78,7 @@ class ImageCompressor @Inject constructor(
|
|||||||
options.inJustDecodeBounds = false
|
options.inJustDecodeBounds = false
|
||||||
val decodedBitmap = BitmapFactory.decodeStream(input, null, options)
|
val decodedBitmap = BitmapFactory.decodeStream(input, null, options)
|
||||||
?: error("Decoding Bitmap from InputStream failed")
|
?: error("Decoding Bitmap from InputStream failed")
|
||||||
val rotatedBitmap = decodedBitmap.rotateToMetadataOrientation(orientation)
|
val rotatedBitmap = decodedBitmap.rotateToExifMetadataOrientation(orientation)
|
||||||
if (resizeMode is ResizeMode.Strict) {
|
if (resizeMode is ResizeMode.Strict) {
|
||||||
rotatedBitmap.resizeToMax(resizeMode.maxWidth, resizeMode.maxHeight)
|
rotatedBitmap.resizeToMax(resizeMode.maxWidth, resizeMode.maxHeight)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+6
-2
@@ -81,8 +81,12 @@ internal class VideoResizer(
|
|||||||
) {
|
) {
|
||||||
fun getOutputSize(inputSize: Size): Size {
|
fun getOutputSize(inputSize: Size): Size {
|
||||||
val resultMajor = min(inputSize.major(), maxSize)
|
val resultMajor = min(inputSize.major(), maxSize)
|
||||||
val aspectRatio = inputSize.major().toFloat() / inputSize.minor().toFloat()
|
val aspectRatio = inputSize.width.toFloat() / inputSize.height.toFloat()
|
||||||
return Size(resultMajor, (resultMajor / aspectRatio).roundToInt())
|
return if (inputSize.width > inputSize.height) {
|
||||||
|
Size(resultMajor, (resultMajor / aspectRatio).roundToInt())
|
||||||
|
} else {
|
||||||
|
Size((resultMajor * aspectRatio).roundToInt(), resultMajor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user