使用dispatchDraw(Canvas)获取视频预览的一小部分
下面是SurfaceView子类中重写的dispatchDraw。我正在尝试更改 Surface 的参数(仅获取视频预览的一小部分。
@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************");
}
为什么上面的代码根本不改变 SurfaceView 的尺寸?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为SurfaceView不使用视图层次结构的Canvas来绘制。
Because SurfaceView does not use the view hierarchy's Canvas to draw.