GWT 图像裁剪与浏览器中的拖放问题
使用 GWT,我在网页上显示图像,我的目标是允许用户裁剪它。用户通过单击图像的特定部分、移动鼠标并在其他地方释放鼠标来绘制假想的边界框。通过使用 MouseDownHandler()
和 MouseUpHandler()
,我计划记录鼠标光标的起始角和结束角。
但是,当我在网络上部署我的工作时,存在这个问题:当用户单击图像并尝试绘制假想的边界框时,网络浏览器(在我的例子中为 Google Chrome)将其检测为拖放操作。
因此,我无法使 mouseDown()
和 mouseUp()
函数正常工作。如何避免浏览器进行拖放操作?
代码:
public void onModuleLoad(){
RootPanel.get().add(img1);
img1.addMouseDownHandler(new MouseDownHandler() {
@Override
public void onMouseDown(MouseDownEvent event) {
startX = event.getX();
startY = event.getY();
}
});
img1.addMouseUpHandler(new MouseUpHandler() {
@Override
public void onMouseUp(MouseUpEvent event) {
endX = event.getX();
endY = event.getY();
img1.setVisibleRect(startX, startY, endX-startX, endY-startY);
}
});
}
Using GWT, I am displaying an image on the web page and my goal is to allow the user to crop it. The user draws an imaginary boundary box by clicking on a specific part of the image, moving the mouse, and releasing it somewhere else. With the use of MouseDownHandler()
and MouseUpHandler()
, I am planning to record the start and end corners of the mouse cursor.
However, when I deploy my work on the web, there is this problem: When the user clicks on the image and tries to draw the imaginary bounding box, the web browser (Google Chrome in my case) detects it as a drag and drop operation.
Therefore, I cannot get my mouseDown()
and mouseUp()
functions to work. How can I avoid the browser to do a drag and drop operation?
The code:
public void onModuleLoad(){
RootPanel.get().add(img1);
img1.addMouseDownHandler(new MouseDownHandler() {
@Override
public void onMouseDown(MouseDownEvent event) {
startX = event.getX();
startY = event.getY();
}
});
img1.addMouseUpHandler(new MouseUpHandler() {
@Override
public void onMouseUp(MouseUpEvent event) {
endX = event.getX();
endY = event.getY();
img1.setVisibleRect(startX, startY, endX-startX, endY-startY);
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你可以使用 HTML5。我在 Stack OverFlow 上发现这个早期问题描述了相同的内容和你一样的问题。我还在 code.google.com 上找到了代码示例
希望这会引导您找到解决方案。
Maybe you can use HTML5. I have found this earlier question here on Stack OverFlow that describes the same problem as you have. Also I found a code example on code.google.com
Hopefully this will lead you to an solution.