简体   繁体   English

GWT:放大和缩小画布图

[英]GWT: Zoom in and zoom out canvas drawing

I want to apply zoom in and zoom out with redrawing objects on canvas so I get clear view at maximum and minimum zoom level. 我想应用放大和缩小在画布上重绘对象 ,以便在最大和最小缩放级别获得清晰的视图。

I get reference how to do it here therefore I have passed my canvas to ScalableImage constructor instead of Image and followed all step. 我得到了如何在这里做的参考,因此我已经将我的画布传递给ScalableImage构造函数而不是Image并遵循所有步骤。
I am redrawing object in "mainDraw" method again but not getting proper result. 我再次在“mainDraw”方法中重绘对象但没有得到正确的结果。 I know I am missing new scale and translate factor for redrawing canvas but no idea how to set for it. 我知道我错过了重新绘制画布的新比例和翻译因素,但不知道如何设置它。 I am drawing multiple objects on canvas like arc, rect etc... hence performance is major concern. 我在画布上绘制了多个对象,如arc,rect等......因此性能是主要关注点。

I have set context.translate(0, canvasHeight); 我设置了context.translate(0,canvasHeight); and context.scale(1, -1); 和context.scale(1,-1); to start coordinate system from bottom left.(As per requirement) 从左下角开始坐标系统。(根据要求)

Below is a sample code with one object and this canvas I am passing to ScalableImage constructor and calling it again in "mainDraw" . 下面是一个带有一个对象的示例代码,我将这个画布传递给ScalableImage构造函数并在“mainDraw”中再次调用它。

int canvasHeight = 600;
int canvasWidth = 600;

Canvas canvas = Canvas.createIfSupported();
Context2d context = pcbCanvas.getContext2d();
canvas.setWidth("600");
canvas.setHeight("600");

canvas.setCoordinateSpaceHeight(canvasHeight);
canvas.setCoordinateSpaceWidth(canvasWidth);

context.translate(0, canvasHeight);
context.scale(1, -1);

context.beginPath();
context.rect(x, y, width, height); 
context.closePath();
context.fill();

RootPanel.get("canvasContainer").add(canvas);

Any reference or any idea? 任何参考或任何想法?
Thanks 谢谢

If you use the back context in my example it should allow you to scale the canvas. 如果你在我的例子中使用后台上下文,它应该允许你缩放画布。 You could also probably modify the constructor to take in another canvas widget instead of an image. 您也可以修改构造函数以获取另一个画布小部件而不是图像。 This might be the best solution. 这可能是最好的解决方案。

In the mainDraw(), you could modify the backContext to add your canvas widget instead of an image. 在mainDraw()中,您可以修改backContext以添加画布小部件而不是图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM