开发者

using dispatchDraw(Canvas) to obtain subsection of video preview

开发者 https://www.devze.com 2023-01-09 03:05 出处:网络
The following is the overriden dispatchDraw in a subclass of SurfaceView. I\'m trying to change the parameters of the Surface(getting only a subsection of the video preview.

The following is the overriden dispatchDraw in a subclass of SurfaceView. I'm trying to change the parameters of the Surface(getting only a subsection of the video preview.

@Override

       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************");

    }

Why does the above code not alter the dimensions of the SurfaceView at all?


Because SurfaceView does not use the view hierarchy's Canvas to draw.

0

精彩评论

暂无评论...
验证码 换一张
取 消