Calculate video output size taking into account portrait mode (#5068)
This commit is contained in:
parent
7c982a30cb
commit
33aa7a914f
3 changed files with 9 additions and 5 deletions
|
|
@ -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].
|
||||
* 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()
|
||||
when (orientation) {
|
||||
ExifInterface.ORIENTATION_ROTATE_270 -> matrix.postRotate(270f)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import android.graphics.BitmapFactory
|
|||
import androidx.exifinterface.media.ExifInterface
|
||||
import io.element.android.libraries.androidutils.bitmap.calculateInSampleSize
|
||||
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.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.core.extensions.runCatchingExceptions
|
||||
|
|
@ -78,7 +78,7 @@ class ImageCompressor @Inject constructor(
|
|||
options.inJustDecodeBounds = false
|
||||
val decodedBitmap = BitmapFactory.decodeStream(input, null, options)
|
||||
?: error("Decoding Bitmap from InputStream failed")
|
||||
val rotatedBitmap = decodedBitmap.rotateToMetadataOrientation(orientation)
|
||||
val rotatedBitmap = decodedBitmap.rotateToExifMetadataOrientation(orientation)
|
||||
if (resizeMode is ResizeMode.Strict) {
|
||||
rotatedBitmap.resizeToMax(resizeMode.maxWidth, resizeMode.maxHeight)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -81,8 +81,12 @@ internal class VideoResizer(
|
|||
) {
|
||||
fun getOutputSize(inputSize: Size): Size {
|
||||
val resultMajor = min(inputSize.major(), maxSize)
|
||||
val aspectRatio = inputSize.major().toFloat() / inputSize.minor().toFloat()
|
||||
return Size(resultMajor, (resultMajor / aspectRatio).roundToInt())
|
||||
val aspectRatio = inputSize.width.toFloat() / inputSize.height.toFloat()
|
||||
return if (inputSize.width > inputSize.height) {
|
||||
Size(resultMajor, (resultMajor / aspectRatio).roundToInt())
|
||||
} else {
|
||||
Size((resultMajor * aspectRatio).roundToInt(), resultMajor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue