User avatar
stolk
Posts: 16
Joined: Tue Jan 22, 2013 3:32 am

screenshot without XWindow running?

Wed Jan 23, 2013 10:12 pm

Hi there,

My app is console-based (uses /opt/vc API.)
How can I make screenshots if I do not have XWindow running?

Either a command line utility, or an API would work for me.

Thanks,

Bram

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: screenshot without XWindow running?

Wed Jan 23, 2013 11:10 pm

Easiest way is to use something like Putty on Windows laptop ssh into the pi and take a screen shot of the Putty session (ALT+Print Screen) same goes with Mac but different client and not sure what the key combo is for screen shot of just a Window and not the whole desktop. This assumes your program can run and output in an ssh session
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: screenshot without XWindow running?

Wed Jan 23, 2013 11:59 pm

Or just Print Screen paste into a graphics package and crop. ;)
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

User avatar
stolk
Posts: 16
Joined: Tue Jan 22, 2013 3:32 am

Re: screenshot without XWindow running?

Thu Jan 24, 2013 12:34 am

I'm pretty sure that the suggestions offered work only if X is running.
So in the end I just decided to add custom code to my app using glReadPixels()

In case someone else needs it. This writes out a dump, albeit top-bottom flipped.

Code: Select all

const char* dumpScreen( void )
{
        static int cnt=0;
        const int w = state->screen_width;
        const int h = state->screen_height;
        const int sz = w*h;
        GLubyte *buffer = (GLubyte *) malloc(4*sz);
        glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, buffer);
        static char fname[128];
        snprintf( fname, 128, "/tmp/dump%02d.ppm", cnt );
        FILE* f = fopen( fname, "wb" );
        fprintf( f, "P6\n%d %d\n255\n", w, h );
        fwrite( buffer, sz*4, 1, f );
        fclose( f );
        free(buffer);
        printf( "dumped screen to '%s'\n", fname );
        cnt++;
        return fname;
}
Bram

efflandt
Posts: 359
Joined: Mon Dec 03, 2012 2:47 am
Location: Elgin, IL USA

Re: screenshot without XWindow running?

Thu Jan 24, 2013 6:55 am

Quick web search for "linux console screen dump" found:
http://www.tldp.org/HOWTO/Keyboard-and- ... TO-20.html

However, you either need to be root or use sudo.

Although, I typically just ssh from Ubuntu into the Pi and use the mouse to highlight, then right click and "copy".

User avatar
stolk
Posts: 16
Joined: Tue Jan 22, 2013 3:32 am

Re: screenshot without XWindow running?

Thu Jan 24, 2013 6:59 am

@efflandt I am not trying to copy the text on the console.
I am trying to copy the graphics that was rendered on the console without XWindow being involved.

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: screenshot without XWindow running?

Thu Jan 24, 2013 8:21 am

I don't know of a way to do this unless you use something like VNC to runn in a window on a PC but thats going to raise it's own issues.

There is one method thats been used on the forum and thats take a photograph of your screen with a digital camera.

This is non invasive and onece the picture is a jpeg you can do whatever you want with it. ;)
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: screenshot without XWindow running?

Fri Jan 25, 2013 4:03 pm

VNC, X forwarding etc. only work if X started - there is no way to get to low-level graphics through Putty etc.

There are however loads of tools to capture the Linux framebuffer: fbcat, scrot, ... and there is always the quick-and-dirty way using 'cat /dev/fb0 >mycapture.raw' (if you don't have the aforementioned tools or do not want to install - or if you use 8 bit mode and the tools fail due to the bcm2708 fb driver not supporting GETPALETTE) - this gives you a raw byte dump of the fb (16 bit 5:6.5 by default) then import into IrfanView (with plugins installed) or similar.

Not 100% sure if the OpenGLES etc rendered stuff is available in the framebuffer though - haven't yet checked...

Dispmanx has it's own dump method vc_dispmanx_snapshot.
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

User avatar
stolk
Posts: 16
Joined: Tue Jan 22, 2013 3:32 am

Re: screenshot without XWindow running?

Fri Jan 25, 2013 5:03 pm

Excellent info, -rst-, just what I was looking for.
Thank you.

Bram

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: screenshot without XWindow running?

Sun Jan 27, 2013 5:03 pm

-rst- wrote:Not 100% sure if the OpenGLES etc rendered stuff is available in the framebuffer though - haven't yet checked...
Well... now checked this and (of course) none of the HW accelerated stuff goes through the framebuffer. As said, dispmanx has it's own screenshot/dump function - I assume EGL may have one as well, or then you have to do your own like stolk did.
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

User avatar
hanzelpeter
Posts: 75
Joined: Mon Jul 09, 2012 11:56 am

Re: screenshot without XWindow running?

Tue Jun 25, 2013 6:57 pm

Hello.

I have tried dispmanx_snapshot and it looks like it is working.
Here is code (main.c)

Code: Select all

// A simple demo using dispmanx to display get screenshot

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <unistd.h>
#include <sys/time.h>

#include "bcm_host.h"

int main(void)
{
    DISPMANX_DISPLAY_HANDLE_T   display;
    DISPMANX_MODEINFO_T         info;
    DISPMANX_RESOURCE_HANDLE_T  resource;
    VC_IMAGE_TYPE_T type = VC_IMAGE_RGB888;
    VC_IMAGE_TRANSFORM_T	transform = 0;
    VC_RECT_T			rect;

    void                       *image;
    uint32_t                    vc_image_ptr;

    int             		ret;

    uint32_t        screen = 0;

    bcm_host_init();

    printf("Open display[%i]...\n", screen );
    display = vc_dispmanx_display_open( screen );

    ret = vc_dispmanx_display_get_info(display, &info);
    assert(ret == 0);
    printf( "Display is %d x %d\n", info.width, info.height );

    image = calloc( 1, info.width * 3 * info.height );

    assert(image);

    resource = vc_dispmanx_resource_create( type,
                                                  info.width,
                                                  info.height,
                                                  &vc_image_ptr );

    vc_dispmanx_snapshot(display, resource, transform);

    vc_dispmanx_rect_set(&rect, 0, 0, info.width, info.height);
    vc_dispmanx_resource_read_data(resource, &rect, image, info.width*3); 

    FILE *fp = fopen("out.ppm", "wb");
    fprintf(fp, "P6\n%d %d\n255\n", info.width, info.height);
    fwrite(image, info.width*3*info.height, 1, fp);
    fclose(fp);

    ret = vc_dispmanx_resource_delete( resource );
    assert( ret == 0 );
    ret = vc_dispmanx_display_close(display );
    assert( ret == 0 );

    return 0;
}
I have currently no monitor attached to PI, but tried hello_pi examples and shopshots looks ok.

nemilos
Posts: 27
Joined: Sat Jan 05, 2013 4:16 am

Re: screenshot without XWindow running?

Wed Oct 30, 2013 6:22 pm

Hello

this code work in horizontal display, but freeze if the display is rotate :(

Return to “Advanced users”