Preserve ratio of image (kinda), 4:3 16:9 9:16
This commit is contained in:
		@@ -177,8 +177,19 @@ class GoodSoftware (private val activity: MainActivity) {
 | 
				
			|||||||
        try {
 | 
					        try {
 | 
				
			||||||
            contentResolver.openInputStream(imageUri)?.use { inputStream ->
 | 
					            contentResolver.openInputStream(imageUri)?.use { inputStream ->
 | 
				
			||||||
                val bitmap = BitmapFactory.decodeStream(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()
 | 
					                val byteArrayOutputStream = ByteArrayOutputStream()
 | 
				
			||||||
                resizedBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream)
 | 
					                resizedBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream)
 | 
				
			||||||
@@ -201,14 +212,17 @@ class GoodSoftware (private val activity: MainActivity) {
 | 
				
			|||||||
        val matrix = android.graphics.Matrix()
 | 
					        val matrix = android.graphics.Matrix()
 | 
				
			||||||
        matrix.postScale(scaleWidth, scaleHeight)
 | 
					        matrix.postScale(scaleWidth, scaleHeight)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        val originalBitmapCopy = Bitmap.createBitmap(bitmap)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        val resizedBitmap = Bitmap.createBitmap(
 | 
					        val resizedBitmap = Bitmap.createBitmap(
 | 
				
			||||||
            bitmap, 0, 0, width, height, matrix, false
 | 
					            originalBitmapCopy, 0, 0, width, height, matrix, false
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        bitmap.recycle()
 | 
					
 | 
				
			||||||
        return resizedBitmap
 | 
					        return resizedBitmap
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private fun requestGalleryPermission() {
 | 
					    private fun requestGalleryPermission() {
 | 
				
			||||||
        ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), REQUEST_GALLERY)
 | 
					        ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), REQUEST_GALLERY)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user