2017-02-07 21 views
5

Şu anda kameranın işlenmesi için textureview numaralı fotoğraf makinesini kullanıyorum. eski android cihazlar ama ben sahip cihazlardaTextureView Translation API üzerinde beklenen beklenmeyen davranış 23 23

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 işin ölçekleme & hesaplama mükemmel iyi: Önizleme Her boyuta olabileceğinden OnSurfaceTextureUpdated çağrıldığında ben textureview değiştirmek için bazı özel kod oluşturduk API düzey 23 ile elimden geldiğimde beklenmedik davranışlar atılır. Galaxy S3

Ama S7:

galaksi S3 doğru görüntüler görüntünün bir sürü kapalı S7

telefon kesintileri, rağmen doğru şekilde konumlandırılması. Bu bana alt kısımların eski cihazlarda nerede oluşturulmadığına inanmamı sağlıyor. Bunu onaylayan ve bu sorunu düzeltmek için doğru konumda bana işaret eden var mı?

cevap

4

Uzun bir testten sonra, sorunun SetTransform yönteminden kaynaklandığını anladım. Ölçekimi matris kullanarak ayarlıyordum ama bu bir şekilde & dokumanı TranslationX & TranslationY göz ardı etti. & matrisini float scaledWidth = width * scaleX ile değiştirerek; float scaledHeight = yükseklik * 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; 

Bazı android aygıtlarda yanlış oluşturma konusunu çözme sorunu giderildi.

İlgili konular