android – TextureView中的抗锯齿

前端之家收集整理的这篇文章主要介绍了android – TextureView中的抗锯齿前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试使用SurfaceView和TextureView播放相同的视频,并注意到使用TextureView渲染的图像比使用SurfaceView更具别名(更不“平滑”).

这是什么原因?有没有办法配置TextureView的渲染看起来更好?

TextureView的用法如下:

  1. TextureView textureView = new TextureView(this);
  2. textureView.setSurfaceTextureListener(new SurfaceTextureListener() {
  3.  
  4. @Override
  5. public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture,int width,int height) {
  6. Log.i("test","onSurfaceTextureAvailable()");
  7. MediaPlayer player = MediaPlayer.create(TestActivity.this,Uri.parse(VIDEO_URL));
  8. Surface surface = new Surface(surfaceTexture);
  9. player.setSurface(surface);
  10. player.start();
  11. }
  12.  
  13. @Override
  14. public void onSurfaceTextureUpdated(SurfaceTexture surface) {
  15. Log.i("test","onSurfaceTextureUpdated()");
  16. }
  17.  
  18. @Override
  19. public void onSurfaceTextureSizeChanged(SurfaceTexture surface,int height) {
  20. Log.i("test","onSurfaceTextureSizeChanged()");
  21. }
  22.  
  23. @Override
  24. public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
  25. Log.i("test","onSurfaceTextureDestroyed()");
  26. return false;
  27. }
  28. });
  29. setContentView(textureView);

而对于SurfaceView:

  1. SurfaceView surfaceView = new SurfaceView(this);
  2. surfaceView.getHolder().addCallback(new Callback() {
  3.  
  4. @Override
  5. public void surfaceCreated(SurfaceHolder holder) {
  6. Log.i("test","surfaceCreated()");
  7. }
  8.  
  9. @Override
  10. public void surfaceDestroyed(SurfaceHolder holder) {
  11. Log.i("test","surfaceDestroyed()");
  12. }
  13.  
  14. @Override
  15. public void surfaceChanged(SurfaceHolder holder,int format,"surfaceChanged()");
  16. MediaPlayer player = MediaPlayer.create(TestActivity.this,Uri.parse(VIDEO_URL));
  17. player.setSurface(holder.getSurface());
  18. player.start();
  19. }
  20. });
  21. setContentView(surfaceView);

解决方法

好吧,似乎在TextureView上应用缩放(除1之外)就可以实现我正在寻找的“平滑”效果.
  1. textureView.setScaleX(1.00001f);

这听起来像是一个奇怪的黑客……但它确实有效.挖掘改变渲染方面的缩放比例会很有趣……

猜你在找的Android相关文章