简体   繁体   English

在我的网页中对第三方小程序进行“截屏”

[英]Take a “screenshot” of 3rd party applet in my webpage

I have a third party Java applet that I am going to embed in my webpage but I don't have access to the applet code. 我有一个第三方Java小程序,该程序将嵌入到我的网页中, 但是我无法访问小程序代码。

But I want to create a button on my page on clicking which will create a screenshot of the applet (but not the whole screen). 但是我想在页面上单击创建一个按钮,该按钮将创建该applet的屏幕截图(而不是整个屏幕)。 I tried using the Robot class but that would take the whole screen which I don't want 我尝试使用Robot类,但是那样会占用整个屏幕,我不需要

BufferedImage screencapture = new Robot().createScreenCapture(
    new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );

I was looking over the net and found code but those require access to the applet which I don't have. 我在网上查找并找到了代码,但是那些代码需要访问我没有的applet。

Is it possible to do it using java? 是否可以使用Java做到这一点? If so, how? 如果是这样,怎么办?

I see at least two options. 我至少看到两个选择。

2nd applet 第二小程序

  • Use a 2nd applet to get a reference to the applet, using AppletContext.getApplet(name) . 使用第二个applet,通过AppletContext.getApplet(name)获得对该applet的引用。
  • Call Applet.getLocationOnScreen() for the co-ordinates. 调用Applet.getLocationOnScreen()作为坐标。
  • It is your page, so unless the applet size is set using percentages, you know the width x height to capture. 这是您的页面,因此,除非使用百分比设置小应用程序的大小,否则您知道要捕获的宽度x高度。
  • Either use sockets to connect to the desktop/CLI app. 使用套接字连接到桌面/ CLI应用程序。 that takes the screen-shot, or use the applet to take the screen-shot. 进行截屏,或使用小程序进行截屏。 Either way, it will require the applet to be trusted. 无论哪种方式,都将要求小应用程序是可信的。

Extend the applet 扩展小程序

Extend the original applet & add a new method to return or export an image of the current applet surface. 扩展原始小程序并添加新方法以返回或导出当前小程序表面的图像。 See ComponentImageCapture.java for an example. 有关示例,请参见ComponentImageCapture.java

Options for exporting the image: 导出图像的选项:

  • Deploy the applet using JWS - use the JNLP file API to export the image to the local file-system. 使用JWS部署applet-使用JNLP文件API将映像导出到本地文件系统。
  • Digitally sign the applet export the image to the local file-system using the more common JFileChooser / File . 使用更常见的JFileChooser / File对小程序进行数字签名,将图像导出到本地文件系统。
  • Pass it back to the host site, which can be done by a sand-boxed applet. 将其传递回宿主站点,这可以通过沙盒小程序完成。

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

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