简体   繁体   English

如何隐藏SWT浏览器或在无头模式下运行?

[英]How to hide SWT Browser or run in headless mode?

I took the rendered page from the SWT Browser and exported it to an image. 我从SWT浏览器中获取了渲染页面并将其导出到图像中。 My problem is that I am not able to get it to export properly when the shell is not visible. 我的问题是,当shell不可见时,我无法正确导出它。 How can I go about hiding the browser and have the image export properly? 如何隐藏浏览器并正确导出图像?

I have tried setting shell.Visible() to false but that messes up the image export. 我已经尝试将shell.Visible()设置为false但是会shell.Visible()图像导出。

This is how I export the image (not sure if this is necessary to the question): 这就是我导出图像的方式(不确定这是否是问题所必需的):

GC source = new GC (shell);  
Image image = new Image(display, browser.getClientArea()); 
source.copyArea(image, 0, 0);
ImageLoader io = new ImageLoader ();
io.data = new ImageData[] { image.getImageData() };
File f = new File (currentDir+"/workpng.png");
io.save (f.getAbsolutePath(), SWT.IMAGE_PNG); 

This might be impossible because the X server/Windows will throw away all rendering commands when the window isn't visible (no point in rendering what you can't see). 这可能是不可能的,因为当窗口不可见时,X服务器/ Windows将丢弃所有渲染命令(渲染无法看到的内容没有任何意义)。

Also what is the client area of the browser in this case? 在这种情况下,浏览器的客户区也是什么?

To make this work, you'll need to allow the shell to open be visible (ie not hidden by some other window). 为了使其工作,您需要允许shell打开可见(即不被其他窗口隐藏)。 Tools like Jenkins use a plugin that starts an X session with Xvfb or Xvnc . 像Jenkins这样的工具使用一个插件来启动与XvfbXvnc的X会话。 After setting the env variable DISPLAY , all UI rendering goes to these sessions. 设置env变量DISPLAY ,所有UI渲染都会转到这些会话。

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

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