Enderezamiento de imagen en Android

Estoy trabajando en un proyecto en el que necesito implementar el enderezamiento de imágenes. Tengo una idea para hacer esto. Estoy rotando la imagen en SeekBar como -10 a +10 grados. Está funcionando por el fondo blanco que es visible cuando giro. Por lo tanto, necesitamos implementar la funcionalidad de zoom también para que se vea como una imagen recta como se muestra a continuación. Por favor consejo con sus sugerencias.

Código de muestra

float a = (float) Math.atan(bmpHeight/bmpWidth);
// the length from the center to the corner of the green
float len1 = (float) ((bmpWidth/2)/Math.cos(a-Math.abs(curRotate)));
// the length from the center to the corner of the black (^ = power)
float len2 = (float) Math.sqrt((bmpWidth/2)^2 + (bmpHeight/2)^2);
// compute the scaling factor
curScale = len2 / len1;
Matrix matrix = new Matrix();
matrix.postScale(curScale, curScale);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmaprotate, 0, 0, bmpWidth, bmpHeight, matrix, true);
mainImage.setImageBitmap(resizedBitmap);

Respuestas a la pregunta(2)

Su respuesta a la pregunta