I am currently making a camera player with textureview to render my camera. Since the preview may have some dimension, I created some kind of custom code to change the texture when OnSurfaceTextureUpdated is OnSurfaceTextureUpdated :
void updateTextureMatrix(int width, int height) { Display display = WindowManager.DefaultDisplay; var isPortrait = (display.Rotation == SurfaceOrientation.Rotation0 || display.Rotation == SurfaceOrientation.Rotation180); int previewWidth = orgPreviewWidth; int previewHeight = orgPreviewHeight; if(isPortrait) { previewWidth = orgPreviewHeight; previewHeight = orgPreviewWidth; } // determine which part to crop float widthRatio = (float)width / previewWidth; float heightRatio = (float)height / previewHeight; float scaleX; float scaleY; if(widthRatio > heightRatio) { // height must be cropped scaleX = 1; scaleY = widthRatio * ((float)previewHeight / height); } else { // width must be cropped scaleX = heightRatio * ((float)previewWidth / width); scaleY = 1; } Android.Graphics.Matrix matrix = new Android.Graphics.Matrix(); matrix.SetScale(scaleX, scaleY); _textureView.SetTransform(matrix); float scaledWidth = width * scaleX; float scaledHeight = height * scaleY; float dx = (width - scaledWidth) * 0.5f; float dy = (height - scaledHeight) * 0.5f; _textureView.TranslationX = dx; _textureView.TranslationY = dy; }
Scaling and calculating dx and dy work fine on older Android devices, but the devices I have with API 23 cause unexpected behavior.
Galaxy S3 displays it correctly: 
But on S7: 
The phone turns off a lot of images, despite the correct positioning. This makes me believe that the lower part is not displayed where it is on older devices. Can someone confirm this and point me in the right position to fix this problem?
source share