简体   繁体   中英

javacv - fast screenshot - how to get image

I just found a good example of JavaCV which using FFmpegFrameGrabber to make screenshot code for linux which supposed to be "fast":

try {
    int x = 0, y = 0, w = 1366, h = 768;
    FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(":0.0+" + x + "," + y);
    grabber.setFormat("x11grab");
    grabber.setImageWidth(w);
    grabber.setImageHeight(h);
    grabber.start();
    CanvasFrame frame = new CanvasFrame("Screen Capture");

    frame.showImage(grabber.grabImage());

    frame.dispose();
    grabber.stop();
} catch (FrameGrabber.Exception ex) {
    ex.printStackTrace();
}

...anyways I'm still not sure how to get image of the screenshot to save in a file. I couldn't find any related example so I do need your advice...

So my question how to get image of screenshot to make possible IO?

Looking at the API of JavaCV , there is an abstract FrameConverter<F> class. The concrete implementation Java2DFrameConverter looks like what you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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