Search in sources :

Example 1 with Bitmap

use of com.teamdev.jxbrowser.ui.Bitmap in project JxBrowser-Examples by TeamDev-IP.

the class BitmapToSwingImage method main.

public static void main(String[] args) throws IOException {
    try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
        Browser browser = engine.newBrowser();
        // Resize browser to the required dimension
        browser.resize(1024, 768);
        // Load the required web page and wait until it is loaded completely
        browser.navigation().loadUrlAndWait("https://www.google.com");
        Bitmap bitmap = browser.bitmap();
        // Convert the bitmap to java.awt.image.BufferedImage
        BufferedImage bufferedImage = BitmapImage.toToolkit(bitmap);
        // Save the image to a PNG file
        ImageIO.write(bufferedImage, "PNG", new File("bitmap.png"));
    }
}
Also used : Bitmap(com.teamdev.jxbrowser.ui.Bitmap) File(java.io.File) Engine(com.teamdev.jxbrowser.engine.Engine) BufferedImage(java.awt.image.BufferedImage) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 2 with Bitmap

use of com.teamdev.jxbrowser.ui.Bitmap in project JxBrowser-Examples by TeamDev-IP.

the class BitmapToJavaFxImage method main.

public static void main(String[] args) throws IOException {
    try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
        Browser browser = engine.newBrowser();
        // Resize browser to the required dimension
        browser.resize(1024, 768);
        // Load the required web page and wait until it is loaded completely
        browser.navigation().loadUrlAndWait("https://www.google.com");
        Bitmap bitmap = browser.bitmap();
        // Convert the bitmap to javafx.scene.image.Image
        Image image = BitmapImage.toToolkit(bitmap);
        // Convert javafx.scene.image.Image to java.awt.image.BufferedImage
        BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null);
        // Save the image to a PNG file
        ImageIO.write(bufferedImage, "PNG", new File("bitmap.png"));
    }
}
Also used : Bitmap(com.teamdev.jxbrowser.ui.Bitmap) BufferedImage(java.awt.image.BufferedImage) BitmapImage(com.teamdev.jxbrowser.view.javafx.graphics.BitmapImage) Image(javafx.scene.image.Image) File(java.io.File) Engine(com.teamdev.jxbrowser.engine.Engine) BufferedImage(java.awt.image.BufferedImage) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 3 with Bitmap

use of com.teamdev.jxbrowser.ui.Bitmap in project JxBrowser-Examples by TeamDev-IP.

the class BitmapToSwtImage method main.

public static void main(String[] args) {
    Display display = new Display();
    try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
        Browser browser = engine.newBrowser();
        // Resize browser to the required dimension
        browser.resize(1024, 768);
        // Load the required web page and wait until it is loaded completely
        browser.navigation().loadUrlAndWait("https://www.google.com");
        Bitmap bitmap = browser.bitmap();
        // Convert the bitmap to org.eclipse.swt.graphics.Image
        Image image = BitmapImage.toToolkit(display, bitmap);
        // Save the image to a PNG file
        ImageLoader loader = new ImageLoader();
        loader.data = new ImageData[] { image.getImageData() };
        loader.save("bitmap.png", SWT.IMAGE_PNG);
    }
    display.dispose();
}
Also used : Bitmap(com.teamdev.jxbrowser.ui.Bitmap) BitmapImage(com.teamdev.jxbrowser.view.swt.graphics.BitmapImage) Image(org.eclipse.swt.graphics.Image) ImageLoader(org.eclipse.swt.graphics.ImageLoader) Engine(com.teamdev.jxbrowser.engine.Engine) Display(org.eclipse.swt.widgets.Display) Browser(com.teamdev.jxbrowser.browser.Browser)

Aggregations

Browser (com.teamdev.jxbrowser.browser.Browser)3 Engine (com.teamdev.jxbrowser.engine.Engine)3 Bitmap (com.teamdev.jxbrowser.ui.Bitmap)3 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2 BitmapImage (com.teamdev.jxbrowser.view.javafx.graphics.BitmapImage)1 BitmapImage (com.teamdev.jxbrowser.view.swt.graphics.BitmapImage)1 Image (javafx.scene.image.Image)1 Image (org.eclipse.swt.graphics.Image)1 ImageLoader (org.eclipse.swt.graphics.ImageLoader)1 Display (org.eclipse.swt.widgets.Display)1