Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] HTML To Image tool


Hi All,
Today i was writing an HTML to image rendering tool using the SWT which works pretty well so far. I have attached to code here too. To this little app i ahve a couple of questions which i wasnt able to do yet.

- capturing a widget image when not visible. When i capture the rendered HTML from the browser widget i need to be visible. I tried to minimize the visibility to only a couple of lines ( see the capture method) but would like to be fully invisible when capturing.

- vertical scroll bar. I cannot get rid of the vertical scroll bar when capturing at the moment i reduce the capturing area by 18 pixels (see capture metohd) but ideally i would prefer not to do that. Is there a way around that?

It would be nice if somebody could give some help on these two questions.

Thanks in advance

roland

public class DocumentationViewer
{
    private Display display;
    private Shell shell;
    private Browser browser;
    private boolean completed = false;
   
    public DocumentationViewer(String a_Url)
    {
        display = new Display();
        shell = new Shell(display);
        shell.setVisible(false);
        shell.setLayout(new FillLayout());

        browser = new Browser(shell, SWT.EMBEDDED | SWT.NO_FOCUS | SWT.NO_REDRAW_RESIZE);
        browser.setUrl(a_Url);
        browser.addProgressListener(new BrowserProgress());  
       
        while (!shell.isDisposed())
        {
            if (!display.readAndDispatch())
            {
                if (completed)
                {
                    capture();
                    completed = false;
                }
                display.sleep();
            }
        }
        display.dispose();
    }
   
    private void capture()
    {
        final GC gc = new GC(browser);
        shell.setVisible(true);
        Point size = browser.getSize();
        final Image image = new Image(display, size.x-18, size.y);
        gc.copyArea(image, 0, 0);
        shell.setVisible(false);
       
        final ImageLoader imageLoader = new ImageLoader();
        imageLoader.data = "" ImageData[] {image.getImageData()};
        imageLoader.save("D:\\foo1.jpg", SWT.IMAGE_JPEG);
        gc.dispose();
        image.dispose();
        System.out.println("captured");
    }
   
    public static void main(String argv[])
        throws Exception
    {
        new DocumentationViewer("http://www.google.com");
    }
   
    public class BrowserProgress implements ProgressListener
    {
        public void changed(ProgressEvent a_Event)
        {
        }

        public void completed(ProgressEvent a_Event)
        {
            completed = true;
        }
    }

Back to the top