2017-02-07 11 views
5

현재 카메라를 렌더하기 위해 textureview 인 카메라 플레이어를 만들고 있습니다. 나이가 안드로이드 기기하지만 난에이 장치에TextureView 번역 API 23의 X 및 Y 예상 동작이 없습니다.

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; 
    } 

dx & dy 작업의 확장 & 계산 완벽하게 정상적으로 : 미리보기 모든 사이즈에 적합있을 수 있으므로 OnSurfaceTextureUpdated를 호출 할 때 나는 textureview을 변경하는 일부 사용자 지정 코드를 만들었습니다 API 레벨 23로 처분하면 예기치 않은 동작이 발생합니다. Galaxy S3

을하지만 S7에 :

은하 S3는 제대로 표시 이미지가 많이 떨어져 S7

전화 인하에도 불구하고 제대로 위치. 이것은 내가 오래된 장치에서 어디서 렌더링되는지 알 수 없게 만듭니다. 누구든지이 사실을 확인하고 정확한 위치에서이 문제를 해결할 수 있습니까?

답변

4

오랫동안 테스트 한 후에 나는 SetTransform 메서드로 인해 문제가 발생했다는 것을 알아 냈습니다. 행렬을 사용하여 스케일을 설정했지만 어떻게 든 내 텍스처 &을 무시한 것은 TranslationX & TranslationY입니다. 행렬 제거 & 로 바꾸기 float scaledWidth = width * scaleX; float scaledHeight = height * scaleY;

 float dx = (width - scaledWidth) * 0.5f; 
     float dy = (height - scaledHeight) * 0.5f; 
     _textureView.ScaleX = scaleX; 
     _textureView.ScaleY = scaleY; 
     _textureView.TranslationX = dx; 
     _textureView.TranslationY = dy; 

일부 안드로이드 기기에서 잘못 렌더링되는 문제가 해결되었습니다.