问题描述
我有很多类似于网上浮动的示例的代码:
I have similar code to many examples floating around the net:
mSurfaceHolder = mVideoSurface.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setFormat(PixelFormat.TRANSPARENT);
mSurfaceHolder.setFixedSize(20, 10);
然后在我拥有的回调中:
Then in the callbacks I have:
@Override public void surfaceCreated(SurfaceHolder holder)
{
Log.d(TAG, "SurfaceCreated");
mSurfaceHolder.setFixedSize(20, 10);
}
@Override public void surfaceChanged(
SurfaceHolder holder, int format, int width, int height
)
{
Log.d(TAG, "SurfaceChanged to " +
format + " width " + width + " height " + height);
}
从此代码中,我希望视频界面为设置为20x10像素的小尺寸,然后缩放到我使用的任何布局尺寸,显示像素化/模糊化的版本.但是,正在播放的视频在其完整的原始分辨率下看起来不错,而不能缩小到20x10.但是我得到了这样的日志:
From this code I would expect the video surface to be set to the tiny size of 20x10 pixels, then scaled back up to whatever layout size I'm using it, showing a pixelated/blurred version. However, the video being played back looks right in its full native resolution, it doesn't scale down to 20x10. But I get logs like these:
SurfaceChanged to -2 width 20 height 10
因此,如果将视频表面设置为这个很小的尺寸,但是从图形上看,视频仍然看起来是高清的,那么设置表面尺寸的用途是什么?
So if the video surface is set to this tiny size, but graphically the video still looks high definition, what is the use of setting the surface size?
可以在 https://github.com/gradha/Stackoverflow38118219 上找到完整的源代码.
Full source code available at https://github.com/gradha/Stackoverflow38118219.
推荐答案
大小对于OpenGL ES之类的东西很重要,您可以在其中以任意大小在Surface上绘制.当您从摄像机或视频解码器发送数据缓冲区时,缓冲区将达到摄像机或视频给定的大小.它的缩放比例与SurfaceView的View的大小匹配,但没有缩放的比例与SurfaceView的Surface的大小匹配.
The size matters for things like OpenGL ES, where you draw on the Surface at whatever size it happens to be. When you're sending buffers of data from the camera or a video decoder, the buffers arrive at whatever size they were given by the camera or video. It's scaled to match the size of the SurfaceView's View, but it's not scaled to match the size of the SurfaceView's Surface.
Camera2预览API是两个概念交叉的地方,在某些情况下,显然它将调整其捕获大小以匹配Surface.
The one place the two concepts cross is with the Camera2 preview API, which will apparently resize its capture to match the Surface in some cases.
您可以在此博客帖子(演示此处),以及有关更多信息此文档中的整个图形体系结构.
You can read more about a primary use case in this blog post (demo here), and more about the graphics architecture as a whole in this doc.
这篇关于调用SurfaceHolder.setFixedSize()有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!