简体   繁体   English

GWT:拍摄小部件的屏幕截图

[英]GWT: take screenshot of widget

For a training project I have to use the Google Web Toolkit to create a small app. 对于培训项目,我必须使用Google Web Toolkit来创建一个小型应用程序。 The app visualizes a dataset either in a table or a map, both can be loaded into a VerticalPanel (which I called mainPanel) and are themselves VerticalPanels. 该应用程序可以在表或地图中可视化数据集,两者都可以加载到VerticalPanel(我称为mainPanel)中,它们本身就是VerticalPanels。

Now the user should be able to get the visualization as an image and save it to his HDD. 现在,用户应该可以将可视化形式获取为图像并将其保存到他的HDD中。 In order to achieve this, I want to screenshot the content of the mainPanel. 为了实现这一点,我想截图mainPanel的内容。

Is this possible? 这可能吗? I've read about HTML5 canvas but this seems to only work in Firefox and only locally. 我已经阅读过有关HTML5 canvas的信息,但这似乎仅在Firefox中有效,并且仅在本地有效。 There must be a way to save the content of a widget as an image, otherwise it wouldn't have gotten the task, but I just can't figure out how. 必须有一种方法可以将小部件的内容另存为图像,否则就无法完成任务,但是我不知道如何实现。

Thank you so much 非常感谢

I think your best bet is to get the HTML from the VerticalPanel (using getElement().getInnerHtml() or something like that). 我认为您最好的选择是从VerticalPanel获取HTML(使用getElement()。getInnerHtml()或类似的东西)。

And then at the server use some library to generate an Image. 然后在服务器上使用一些库来生成图像。

A quick google I found https://code.google.com/p/java-html2image/wiki/HtmlImageGenerator 我找到了一个快速的Google https://code.google.com/p/java-html2image/wiki/HtmlImageGenerator

And finally send this back to the client. 最后将其发送回客户端。

Not really an easy task for people learning GWT however. 然而,对于学习GWT的人来说,这并不是一件容易的事。

I don't think a client side only solution, working on all browsers, is possible. 我认为不可能在所有浏览器上使用仅客户端解决方案。

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

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