Make screenshot of work display.

classic Classic list List threaded Threaded
37 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Pixelapp
But go ahead and try the problem yourself, though.
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Andriy
Ok, as now I research I saw that the best way use Direct capture, I also may be to try jogl, but with my low experiace I can't do it quick.
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Andriy
Hi, Pixelapp, what about jogl screen code, you tell me to remember you.
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Pixelapp
Ok, I get it.

If I get anything working I'll be sure to post it here. Ok.
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Pixelapp
This post was updated on .
In reply to this post by Andriy
Ok Andriy, here is the code:

            try
            {
                        BufferedImage tScreenshot = Screenshot.readToBufferedImage(0,0, 600, 600, false);
                        File tScreenCaptureImageFile = new File("src/yourpa/ckage/hello.png");
                        ImageIO.write(tScreenshot, "png", tScreenCaptureImageFile);
            }
            catch (IOException ioe)
            {
                System.out.println (ioe.getMessage ());
            }

To avoid the error you get, I suggest you put this code at the end of the display() method. And since you will be using the animator, lower the frame rate to 1 frame per second otherwise it will crash during this test.

Moreover, judging by the fact that this class was developed by Jogampers I expect it to be of high quality and a really fast class. Therefore I'm sticking to this class to develop my project much further.

Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Andriy
Hi, Pixelapp, I am new in jogl and opengl conception at all, may be it simple question but I need simple code of main class include animator also, witch create work screen of desktop, I it isn't difficult write for me this code please. I need first to test this to think really it for me.
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Pixelapp
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Andriy
I saw this codes early and do thomething of those examples, but I cann't understand how to create desktop screenshot, as I now know to create screenshot I need gdrawable context, how I get a desktop context, how to put all desktop to canvas???You try to create screenshot of desktop???If try please show me your code, I want to see it. Now I don't see only the way to use jna and system api for my problem.
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Pixelapp
This code tells you exactly what you are asking.
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Andriy
Good, this is code:
package test;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;
import com.jogamp.opengl.util.awt.Screenshot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class JOGLCapture implements GLEventListener {

    private double theta = 0;
    private double s = 0;
    private double c = 0;

    public static void main(String[] args) {
        GLProfile glp = GLProfile.getDefault();
        GLCapabilities caps = new GLCapabilities(glp);
        GLCanvas canvas = new GLCanvas(caps);

        Frame frame = new Frame("AWT Window Test");
        frame.setSize(300, 300);
        frame.add(canvas);
        frame.setVisible(true);

        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        canvas.addGLEventListener(new JOGLCapture());

        FPSAnimator animator = new FPSAnimator(canvas, 60);
        animator.add(canvas);
        animator.start();
    }

    @Override
    public void display(GLAutoDrawable drawable) {
        update();
        render(drawable);
          try
            {
                        BufferedImage tScreenshot = Screenshot.readToBufferedImage(0,0, 600, 600, false);
                        File tScreenCaptureImageFile = new File("/home/android/hello.png");
                        ImageIO.write(tScreenshot, "png", tScreenCaptureImageFile);
                        System.exit(0);
            }
            catch (IOException ioe)
            {
                System.out.println (ioe.getMessage ());
            }
    }

    @Override
    public void dispose(GLAutoDrawable drawable) {
    }

    @Override
    public void init(GLAutoDrawable drawable) {
    }

    @Override
    public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    }

    private void update() {
        theta += 0.01;
        s = Math.sin(theta);
        c = Math.cos(theta);
    }

    private void render(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();

        gl.glClear(GL.GL_COLOR_BUFFER_BIT);

        // draw a triangle filling the window
        gl.glBegin(GL.GL_TRIANGLES);
        gl.glColor3f(1, 0, 0);
        gl.glVertex2d(-c, -c);
        gl.glColor3f(0, 1, 0);
        gl.glVertex2d(0, c);
        gl.glColor3f(0, 0, 1);
        gl.glVertex2d(s, -s);
        gl.glEnd();
    }
}

I have only a screen of java frame, and what about all desktop screenshot??
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Pixelapp
Delete this "System.exit(0);"
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Andriy
And how it help me????Delete but work screen of display don't get.
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Pixelapp
So, what's your problem again?
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

gouessej
Administrator
In reply to this post by Andriy
What are you trying to achieve? You can only get a screenshot of the current content of a canvas, not the whole desktop.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Andriy
I know this, but I want to know can jogl get a screenshot of desktop?If it can, how ???
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

Pixelapp
"What are you trying to achieve? You can only get a screenshot of the current content of a canvas, not the whole desktop."

I second that.
Reply | Threaded
Open this post in threaded view
|

Re: Make screenshot of work display.

gouessej
Administrator
In reply to this post by Andriy
Maybe you can do that with a maximized transparent window.

You can use Screencast-O-Matic or Have2Chat Screencast, the latter is entirely written in Java, its author is a nice guy, you should contact him if you need some help. Good luck.
Julien Gouesse | Personal blog | Website
12