我正在为CameraPreview使用TextureView。由于显示比和预览比我使用之间的差 textureView.setTransform(matrix)在onSurfaceTextureAvailable()用于缩放的预览。当我需要TextureView的屏幕截图时,我使用textureView.getBitmap(),但是在某些智能手机型号中,getBitmap()忽略预览的缩放比例。为什么会发生?
当我需要在显示相机预览之前对其进行后处理时,我发现了同样的问题。
看起来原始相机捕获的是 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 );
Run Code Online (Sandbox Code Playgroud)
我确实注意到位图没有像原始视图中那样被裁剪。就我而言,TextureView 已经裁剪了图像的顶部和底部,而位图仍然是全尺寸的。基本上,TextureView 看起来默认使用“centerCrop”的等效项来显示原始源。我设置了要使用的相应 ImageView,android:scaleType="centerCrop"并且视图具有相同的方面。
当然,这意味着我正在处理更多我真正需要的图像,但我还没有弄清楚如何在处理之前准确裁剪出TextureView正在执行的操作。
| 归档时间: |
|
| 查看次数: |
1189 次 |
| 最近记录: |