1. 程式人生 > >Android 視訊縮放/放大

Android 視訊縮放/放大

1. 原理

不直接改變Codec輸出的視訊寬高比,而是改變視訊播放器視窗的大小。

2. 設定Window

需要將Window設定未可以超出螢幕尺寸

mWindow.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);


3. SurfaceView保持寬高比

mSurfaceHolder.setFixedSize(mVideoWidth, mVideoHeight);

4. 改變Surface視窗大小

ViewGroup.LayoutParams layoutParams = (ViewGroup.LayoutParams) mSurface.getLayoutParams();
if (scale > 4.0f) {
    scale = 4.0f;
} else if (scale < 0.25f) {
    scale = 0.25f;
}
layoutParams.width = (int) (windowWidth * scale);
layoutParams.height = (int) (windowHeight * scale);

mSurface.setLayoutParams(layoutParams);