问题描述
我试图用 SurfaceView
和 TextureView
播放相同的视频,发现图像渲染与 TextureView
更别名(少'平稳')高于 SurfaceView
。
,这是什么原因呢?有什么办法来配置渲染 TextureView
的更好看?
在 TextureView
使用这样的:
TextureView textureView =新TextureView(本);
textureView.setSurfaceTextureListener(新SurfaceTextureListener(){
@覆盖
公共无效onSurfaceTextureAvailable(表面纹理表面纹理,诠释的宽度,高度INT){
Log.i(测试,onSurfaceTextureAvailable());
的MediaPlayer播放器= MediaPlayer.create(TestActivity.this,Uri.parse(VIDEO_URL));
面面=新的表面(表面纹理);
player.setSurface(面);
player.start();
}
@覆盖
公共无效onSurfaceTextureUpdated(表面表面纹理){
Log.i(测试,onSurfaceTextureUpdated());
}
@覆盖
公共无效onSurfaceTextureSizeChanged(表面表面纹理,诠释的宽度,高度INT){
Log.i(测试,onSurfaceTextureSizeChanged());
}
@覆盖
公共布尔onSurfaceTextureDestroyed(表面表面纹理){
Log.i(测试,onSurfaceTextureDestroyed());
返回false;
}
});
的setContentView(textureView);
和的 SurfaceView
:
SurfaceView surfaceView =新SurfaceView(本);
surfaceView.getHolder()的addCallback(新的回调(){
@覆盖
公共无效surfaceCreated(SurfaceHolder持有者){
Log.i(测试,surfaceCreated());
}
@覆盖
公共无效surfaceDestroyed(SurfaceHolder持有者){
Log.i(测试,surfaceDestroyed());
}
@覆盖
公共无效surfaceChanged(SurfaceHolder持有人,INT格式,诠释的宽度,高度INT){
Log.i(测试,surfaceChanged());
的MediaPlayer播放器= MediaPlayer.create(TestActivity.this,Uri.parse(VIDEO_URL));
player.setSurface(holder.getSurface());
player.start();
}
});
的setContentView(surfaceView);
嗯,好像是应用分级(除1)在TextureView做的平滑的效果,我正在寻找。
textureView.setScaleX(1.00001f);
这听起来像一个奇怪的黑客攻击......但它的工作原理。将是有趣挖掘出了什么事在改变渲染方面的比例做了...
I tried to play the same video with a SurfaceView
and a TextureView
and noticed that the image rendered with the TextureView
is more aliased (less 'smooth') than with the SurfaceView
.
What is the reason for this ? Is there any way to configure rendering of TextureView
to look better ?
The TextureView
is used like this:
TextureView textureView = new TextureView(this);
textureView.setSurfaceTextureListener(new SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
Log.i("test", "onSurfaceTextureAvailable()");
MediaPlayer player = MediaPlayer.create(TestActivity.this, Uri.parse(VIDEO_URL));
Surface surface = new Surface(surfaceTexture);
player.setSurface(surface);
player.start();
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
Log.i("test", "onSurfaceTextureUpdated()");
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
Log.i("test", "onSurfaceTextureSizeChanged()");
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.i("test", "onSurfaceTextureDestroyed()");
return false;
}
});
setContentView(textureView);
And for the SurfaceView
:
SurfaceView surfaceView = new SurfaceView(this);
surfaceView.getHolder().addCallback(new Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.i("test", "surfaceCreated()");
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.i("test", "surfaceDestroyed()");
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.i("test", "surfaceChanged()");
MediaPlayer player = MediaPlayer.create(TestActivity.this, Uri.parse(VIDEO_URL));
player.setSurface(holder.getSurface());
player.start();
}
});
setContentView(surfaceView);
Well, it seems that applying a scaling (other than 1) on the TextureView does the 'smoothing' effect that I'm looking for.
textureView.setScaleX(1.00001f);
That sounds like a strange hack...but it works. Would be interesting to dig out what's done in the scaling that changes the rendering aspect...
这篇关于抗锯齿在TextureView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!