0

下面是在 SurfaceView 的子类中重写的 dispatchDraw。我正在尝试更改 Surface 的参数(仅获取视频预览的一小部分。

@覆盖

       public void dispatchDraw (Canvas canvas) {
        Log.d(TAG,"**************inside dispatchDraw************");

        int VIEW_WIDTH = canvas.getWidth(); 
        int VIEW_HEIGHT = canvas.getHeight();
        Log.d(TAG,"**************inside dispatchDraw************" + Integer.toString(VIEW_WIDTH) + " ," + Integer.toString(VIEW_HEIGHT));

        int newWidth = 400;  

        int newHeight = 240; 
        float scaleWidth = ((float) newWidth) / VIEW_WIDTH;  

        float scaleHeight = ((float) newHeight) / VIEW_HEIGHT;  


        Matrix matrix = new Matrix();  

        matrix.postScale(scaleWidth, scaleHeight);  

        canvas.setMatrix(matrix);
        super.dispatchDraw(canvas);
        Log.d(TAG,"**************inside dispatchDraw-after super************");

    }

为什么上面的代码根本没有改变 SurfaceView 的尺寸?

4

1 回答 1

1

因为 SurfaceView 不使用视图层次结构的 Canvas 进行绘制。

于 2010-07-29T06:31:33.827 回答