fix images using wrong width/height

- takes the exit rotation into account as the bitmap can provide misleading values
This commit is contained in:
Adam Brown 2022-10-30 18:40:50 +00:00
parent 2ad4ca1c61
commit a0e56b349c
2 changed files with 8 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import android.content.ContentResolver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.media.ExifInterface
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.provider.OpenableColumns import android.provider.OpenableColumns
@ -295,9 +296,14 @@ internal class AndroidImageContentReader(private val contentResolver: ContentRes
cursor.getLong(columnIndex) cursor.getLong(columnIndex)
} ?: throw IllegalArgumentException("Could not process $uri") } ?: throw IllegalArgumentException("Could not process $uri")
val shouldSwapSizes = ExifInterface(contentResolver.openInputStream(androidUri) ?: throw IllegalArgumentException("Could not process $uri")).let {
val orientation = it.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
orientation == ExifInterface.ORIENTATION_ROTATE_90 || orientation == ExifInterface.ORIENTATION_ROTATE_270
}
return ImageContentReader.ImageContent( return ImageContentReader.ImageContent(
height = options.outHeight, height = if (shouldSwapSizes) options.outWidth else options.outHeight,
width = options.outWidth, width = if (shouldSwapSizes) options.outHeight else options.outWidth,
size = fileSize, size = fileSize,
mimeType = options.outMimeType, mimeType = options.outMimeType,
fileName = androidUri.lastPathSegment ?: "file", fileName = androidUri.lastPathSegment ?: "file",

View File

@ -60,7 +60,6 @@ internal class SendMessageUseCase(
private suspend fun imageMessageRequest(message: Message.ImageMessage): HttpRequest<ApiSendResponse> { private suspend fun imageMessageRequest(message: Message.ImageMessage): HttpRequest<ApiSendResponse> {
val imageMeta = message.content.meta val imageMeta = message.content.meta
return when (message.sendEncrypted) { return when (message.sendEncrypted) {
true -> { true -> {
val result = mediaEncrypter.encrypt(imageContentReader.inputStream(message.content.uri)) val result = mediaEncrypter.encrypt(imageContentReader.inputStream(message.content.uri))