Preserve ratio of image (kinda), 4:3 16:9 9:16
This commit is contained in:
parent
7f9f5d30a1
commit
38b9eecc2a
@ -177,8 +177,19 @@ class GoodSoftware (private val activity: MainActivity) {
|
||||
try {
|
||||
contentResolver.openInputStream(imageUri)?.use { inputStream ->
|
||||
val bitmap = BitmapFactory.decodeStream(inputStream)
|
||||
val width = bitmap.width
|
||||
val height = bitmap.height
|
||||
println("Width: $width, Height: $height")
|
||||
|
||||
// Determine the orientation of the image
|
||||
val resizedBitmap = if (width > height) {
|
||||
resizeBitmap(bitmap, 1920, 1080)
|
||||
} else if (width < height) {
|
||||
resizeBitmap(bitmap, 1080, 1920)
|
||||
} else {
|
||||
resizeBitmap(bitmap, 1440, 1080)
|
||||
}
|
||||
|
||||
val resizedBitmap = resizeBitmap(bitmap, 1920, 1080)
|
||||
|
||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||
resizedBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream)
|
||||
@ -201,14 +212,17 @@ class GoodSoftware (private val activity: MainActivity) {
|
||||
val matrix = android.graphics.Matrix()
|
||||
matrix.postScale(scaleWidth, scaleHeight)
|
||||
|
||||
val originalBitmapCopy = Bitmap.createBitmap(bitmap)
|
||||
|
||||
val resizedBitmap = Bitmap.createBitmap(
|
||||
bitmap, 0, 0, width, height, matrix, false
|
||||
originalBitmapCopy, 0, 0, width, height, matrix, false
|
||||
)
|
||||
bitmap.recycle()
|
||||
|
||||
return resizedBitmap
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun requestGalleryPermission() {
|
||||
ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), REQUEST_GALLERY)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user