我正在为CameraPreview使用TextureView。由于显示比率和预览比率之间存在差异,因此我使用onSurfaceTextureAvailable()
中的textureView.setTransform(matrix)
来缩放预览。当我需要textureView的屏幕截图时,我会使用textureView.getBitmap()
,但在某些型号的智能手机中,getBitmap()
会忽略预览的缩放。为什么会发生这种情况?
发布于 2015-01-23 03:17:39
当我需要在显示相机预览之前对其进行后处理时,我发现了同样的问题。
看起来,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 );
我将相应的ImageView设置为使用android:scaleType="centerCrop"
,视图具有相同的方面。
当然,这意味着我正在处理更多我真正需要的图像,但我还没有弄清楚如何在处理之前准确地裁剪出TextureView正在做什么。
https://stackoverflow.com/questions/27300975
复制相似问题