2014-12-04 58 views
2

由於顯示比率和預覽比率之間的差異,我使用TextureView for CameraPreview,我使用onSurfaceTextureAvailable()中的textureView.setTransform(matrix)來縮放預覽。當我需要紋理視圖的屏幕截圖時,我使用了textureView.getBitmap(),但在某些智能手機模型中,getBitmap()忽略預覽的縮放比例。爲什麼會發生?textureview getbitmap忽略setTransform

回答

2

當我需要在顯示相機預覽之前進行後期處理時,我發現了同樣的問題。

它看起來像原始相機捕獲是什麼出現在getBitmap()而不是最終被顯示的轉換視圖。

我工作圍繞這一問題與以下,這只是應用相同的變換位圖被拉出來後:

TextureView textureView = (TextureView) findViewById(R.id.texture); 
Matrix m = new Matrix(); 
// Do matrix creation here. 
textureView.setTransform(m); 

// When you need to get the Bitmap 
Bitmap bitmap = textureView.getBitmap(); 
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), textureView.getTransform(null), true); 

我也注意到,位圖不被裁剪像它可能是在原視圖。在我的情況下,TextureView已經裁剪了圖像的頂部和底部,而位圖仍然是全尺寸的。基本上,它看起來像TextureView默認使用等價的「centerCrop」顯示原始源。我將相應的ImageView設置爲使用android:scaleType="centerCrop",並且視圖具有相同的方面。

當然,這意味着我正在處理更多我真正需要的圖像,但我還沒有弄清楚如何在處理之前精確地顯示TextureView正在做什麼。