@@ -600,35 +600,39 @@ class GeoTagImage(
600600
601601 bitmap = processBitmapAspectRatio(bitmap)
602602
603- val resizedBitmap = when (cameraAspectRatio) {
604- RATIO_1X1 -> bitmap.scale(1024 , 1024 )
605- RATIO_16X9 -> bitmap.scale(720 , 1280 )
606- RATIO_FULL -> {
607- val maxSide = 1280
608- val width = bitmap.width
609- val height = bitmap.height
610-
611- if (width >= height) {
612- val ratio = height.toFloat() / width
613- bitmap.scale(maxSide, (maxSide * ratio).toInt())
614- } else {
615- val ratio = width.toFloat() / height
616- bitmap.scale((maxSide * ratio).toInt(), maxSide)
603+ if (useCameraX) {
604+ bitmap = when (cameraAspectRatio) {
605+ RATIO_1X1 -> bitmap.scale(1024 , 1024 )
606+ RATIO_16X9 -> bitmap.scale(720 , 1280 )
607+ RATIO_FULL -> {
608+ val maxSide = 1280
609+ val width = bitmap.width
610+ val height = bitmap.height
611+
612+ if (width >= height) {
613+ val ratio = height.toFloat() / width
614+ bitmap.scale(maxSide, (maxSide * ratio).toInt())
615+ } else {
616+ val ratio = width.toFloat() / height
617+ bitmap.scale((maxSide * ratio).toInt(), maxSide)
618+ }
617619 }
618- }
619620
620- else -> bitmap.scale(768 , 1024 )
621+ else -> bitmap.scale(768 , 1024 )
622+ }
623+ } else {
624+ bitmap = scaleToMaxSide(bitmap)
621625 }
622626
623627 if (! geoTagged) {
624- saveImageToGallery(resizedBitmap )
628+ saveImageToGallery(bitmap )
625629 val outputStream = file.outputStream()
626- resizedBitmap .compress(Bitmap .CompressFormat .JPEG , 80 , outputStream)
630+ bitmap .compress(Bitmap .CompressFormat .JPEG , 80 , outputStream)
627631 outputStream.close()
628632 return Uri .fromFile(file)
629633 }
630634
631- val geoTaggedBitmap = drawTextOnBitmap(resizedBitmap )
635+ val geoTaggedBitmap = drawTextOnBitmap(bitmap )
632636
633637 saveImageToGallery(geoTaggedBitmap)
634638
@@ -643,6 +647,25 @@ class GeoTagImage(
643647 return null
644648 }
645649
650+ private fun scaleToMaxSide (bitmap : Bitmap , maxSide : Int = 1024): Bitmap {
651+ val width = bitmap.width
652+ val height = bitmap.height
653+
654+ if (width <= maxSide && height <= maxSide) return bitmap
655+
656+ val ratio = if (width >= height) {
657+ maxSide.toFloat() / width
658+ } else {
659+ maxSide.toFloat() / height
660+ }
661+
662+ val newWidth = (width * ratio).toInt()
663+ val newHeight = (height * ratio).toInt()
664+
665+ return bitmap.scale(newWidth, newHeight)
666+ }
667+
668+
646669 private fun embedGeoTagInExif (filePath : String , location : Location ) {
647670 try {
648671 val exif = ExifInterface (filePath)
0 commit comments