Copy the current image of the screen to file

Someone at - it a code that will copy what is on the screen of an application and write it in an image file?  This way the user can save what is currently on the screen of the app for later.

It took some digging so I amo put my final code of work here for someone else:

void mainapp::write_bitmap_header(int nbytes, QByteArray& ba, const int size[])
{
    char header[54];

    /* Set standard bitmap header */
    header[0] = 'B';
    header[1] = 'M';
    header[2] = nbytes & 0xff;
    header[3] = (nbytes >> 8) & 0xff;
    header[4] = (nbytes >> 16) & 0xff;
    header[5] = (nbytes >> 24) & 0xff;
    header[6] = 0;
    header[7] = 0;
    header[8] = 0;
    header[9] = 0;
    header[10] = 54;
    header[11] = 0;
    header[12] = 0;
    header[13] = 0;
    header[14] = 40;
    header[15] = 0;
    header[16] = 0;
    header[17] = 0;
    header[18] = size[0] & 0xff;
    header[19] = (size[0] >> 8) & 0xff;
    header[20] = (size[0] >> 16) & 0xff;
    header[21] = (size[0] >> 24) & 0xff;
    header[22] = -size[1] & 0xff;
    header[23] = (-size[1] >> 8) & 0xff;
    header[24] = (-size[1] >> 16) & 0xff;
    header[25] = (-size[1] >> 24) & 0xff;
    header[26] = 1;
    header[27] = 0;
    header[28] = 32;
    header[29] = 0;
    header[30] = 0;
    header[31] = 0;
    header[32] = 0;
    header[33] = 0;
    header[34] = 0; /* image size*/
    header[35] = 0;
    header[36] = 0;
    header[37] = 0;
    header[38] = 0x9;
    header[39] = 0x88;
    header[40] = 0;
    header[41] = 0;
    header[42] = 0x9l;
    header[43] = 0x88;
    header[44] = 0;
    header[45] = 0;
    header[46] = 0;
    header[47] = 0;
    header[48] = 0;
    header[49] = 0;
    header[50] = 0;
    header[51] = 0;
    header[52] = 0;
    header[53] = 0;

    ba.append(header, sizeof(header));
}

void mainapp::capture()
{
        screen_pixmap_t screen_pix;
    screen_buffer_t screenshot_buf;
    char *screenshot_ptr = NULL;
    int screenshot_stride = 0;
    screen_context_t context;
    screen_create_context(&context, 0);
    int usage, format;
    int size[2];

    screen_create_pixmap(&screen_pix, context);

    usage = SCREEN_USAGE_READ | SCREEN_USAGE_NATIVE;
    screen_set_pixmap_property_iv(screen_pix, SCREEN_PROPERTY_USAGE, &usage);

    format = SCREEN_FORMAT_RGBA8888;
    screen_set_pixmap_property_iv(screen_pix, SCREEN_PROPERTY_FORMAT, &format);

    int width = 720 ;
    int height = 1280;
    size[0] = width;
    size[1] = height;
    screen_set_pixmap_property_iv(screen_pix, SCREEN_PROPERTY_BUFFER_SIZE, size);

    screen_create_pixmap_buffer(screen_pix);
    screen_get_pixmap_property_pv(screen_pix, SCREEN_PROPERTY_RENDER_BUFFERS,
                                  (void**)&screenshot_buf);
    screen_get_buffer_property_pv(screenshot_buf, SCREEN_PROPERTY_POINTER,
                                  (void**)&screenshot_ptr);
    screen_get_buffer_property_iv(screenshot_buf, SCREEN_PROPERTY_STRIDE,
                                  &screenshot_stride);

    screen_read_window(Application::instance()->mainWindow()->handle(), screenshot_buf, 0, NULL ,0);

    QByteArray array;

    int nbytes = size[0] * size[1] * 4;
    write_bitmap_header(nbytes, array, size);

    for (int i = 0; i < size[1]; i++)
    {
        array.append(screenshot_ptr + i * screenshot_stride, size[0] * 4);
    }

    QImage image = QImage::fromData(array, "BMP");
    QFile outFile("shared/photos/temp1.jpeg");
    outFile.open(QIODevice::WriteOnly);
    image.save(&outFile, "JPEG");

    screen_destroy_pixmap(screen_pix);
}

Tags: BlackBerry Developers

Similar Questions

  • Device not detected, I copied the Diagonstic report file...

    I copied the Diagonstic report file.  It shows me:

    Win32_PNPEntity.DeviceID="ACPI\\ENE0201\\3&11583659&0".

    the following line of Code ConfigManagerError (red flag)

    the following line: ConfigManagerUserConfig 0

    the last line: status: error

    This is a FEATURE 'UNKNOWN '.

    Ben Berzins

    http://support.Lenovo.com/en_GB/downloads/default.page? #

    There are a number of models Y550, you should have a shortcut of Lenovo desktop update

  • Is it possible to copy the screen background image to 'restore' a lost image?

    My wife accidentally resized the image of our daughter that we do not have a backup on however, this image is currently set as the desktop wallpaper. I hope that there is a way to recover the image by simply copying the copy of Windows that he uses as his wallpaper. Is this possible or am I out of luck?

    You're out of luck if the image used as the background is the same as that which your resized wife. If resized is in a different place or was named differently, so it has not been overwritten. However, all is not entirely lost.

    If you have Vista Business/Ultimate/Enterprise, you also have the functionality of previous Versions. If you have only Vista Home Basic or Premium, this feature is not available for you. Explorer shadow of third parties may be able to help, however.

    http://www.ShadowExplorer.com/downloads.html

    I would download the latest stable version, 0.4 instead of using the beta version. MS - MVP - Elephant Boy computers - don't panic!

  • apply the group policy for the screen saver without copying the screen saver on all computers

    Hello
    I have applied the group policy for server screen saver 2008 but do run
    I copied the file on each computer .scr.
    is there a way to push file of screen directly from the server without copying it to each computer on the network?
    or is there a software that can automatically run the screensaver on the network?

    Hello

    The business support, you can find forums on TechNet, see the following links:

    http://social.technet.Microsoft.com/forums/en/category/WindowsServer/

    http://social.technet.Microsoft.com/forums/en/category/w7itpro/

  • Where is the screen saver files in Windows Vista?

    I found a cool screensaver that I would use, but I don't know where to copy EXACTLY. I am running Windows Vista and there is not an installer with it. I tried to find the other folders/files screensaver but am not having much luck and there is not much information I can find. Help!

    Hi Dave,.

    The files (.scr) screensaver in Vista are found in C:\Windows\System32.  You can search in this place the .scr file you want.

    For more information on the screen savers, you can consult the following article:

    Change screen saver

    Hope this information is useful.

  • Setup cannot copy the c_20936.nl file during the installation of additional languages

    original title: Setup cannot copy the file c_20936.nl
     
    I have windows xp sp3 and try to install additional languages, East Asian and I get this error on copy. "Setup cannot copy the file c_20936.nl. Make sure that the disk in the Windows XP Professional CD is in the drive selected below, or provide the location where the file is located. "Copy the files: D:\j386. Need help, what can I do, I have the correct cd in the cd drive, but I get the error of copying.

    Hello

    Step 1:

    I suggest that you try to copy the folder i368 on the computer, and then try to install it from there and check if it installs.

    Step 2:

    Follow the steps mentioned below.

    a. Click Start and then click Control Panel.

    b. double-click regional and Language Options.

    c. click on the languages tab, click details and then click Add.

    d. under input language, add the language that you want to use.

    e. under Configuration keyboard/IME, click the keyboard layout that you want, and then click OK.

    Check the links below.

    List of languages supported in Windows 2000, Windows XP and Windows Server 2003

    http://support.Microsoft.com/kb/292246

    How to add and enable additional languages in Windows

    http://support.Microsoft.com/kb/177561

    Download languages for Windows

    http://Windows.Microsoft.com/en-us/Windows/downloads/languages-XP

  • How to remove the screen saver file?

    I'm losing all my icons because of my screensaver file is bad, please help me remove this file. Thank you... JAY PATEL.

    Hello

    1 are. what screensaver and icons you referring?
    2 have you installed any third-party screen saver file?
    3. what exactly is the problem?

    Your question does contain all the required information necessary for us to help you. Please re - write your question, this time make sure you have all the information necessary and we will try to help.
    How to ask a question
    http://support.Microsoft.com/kb/555375

    If you try to uninstall third-party screen saver then the article below might help you to do.
    How to change or remove a program in Windows XP
    http://support.Microsoft.com/kb/307895

  • The Windows Vista startup disk crashes after the screen "loading files".

    I am trying to install Windows Vista on a new computer. The computer recognizes the boot disk and I can go beyond the "Loading files" screen, but when I get to the screen that looks like the standard login screen, the menu to install Windows never appears. The display will be just what it was. Any help would be appreciated.

    Hello Trey

    I suggest you see if there is an update of the bios for the motherboard. You can also check out the link below and see the suggestion given by Tim Quan.
  • Using copyTo to copy the Sqlite database file to the directory of the user

    I am trying to copy my database Sqlite directory of private enforcement directory of documents accessible to the user. Here is my code:

    // closing db connection
    dbConnection.close();
    // clearing the db file variable
    dbFile = null;
    
    // new handle on the same db file
    dbFile = File.applicationStorageDirectory.resolvePath("mydb.db");
    // copy to documents directory
    dbFile.copyTo(File.documentsDirectory);
    

    When I try to run the code on the device, I get:

    There is an example on the Adobe AIR help page:

    original var = air. File.documentsDirectory.resolvePath ("AIR Test/test.txt");

    newFile var = air. File.documentsDirectory.resolvePath ("AIR Test/copy.txt");

    original.copyTo (newFile, true); true means crushes!

    Therefore, specify the new file name too not only the directory.

  • I would like to know how I can copy the screen and paste on a mail using the function key

    I'm trying to show my screen by copying and then paste it into an email.

    Hello

    try this hold down CTRL + Prtscr, SysRq and open paint and paste is if possible try ctrl + v else goto bar menu option edit and paste
    the majority of the mailbox advanced after using CTRL + Prtscr, SysRq can take the image directly paste in
    Let me know if there no
  • FireFox does not start due to message ssl3.dll is missing, and indeed it is not in the folder program files. But I can't seem to be able to reinstall Firefox or copy the ssl3.dll file in the program folder files. Help?

    Webroot identified ssl3.dll as a threat and deleted. Now, I can't start Firefox, nor can I copy ssl3.dll in the file Firefox program. I tried to uninstall Firefox and reinstall, but it always shows an update and does not seem to add ssl3.dll. Help?

    See also [904266/questions/904266]

  • I've lost the bar at the top of the screen. FILE, EDIT, HISTORY, BOOKMARKS etc how do I get it back?

    It might have something to do with a change that I did yesterday. I followed some instructions that said to go to TOOLS, then click on clear Cache. Now it isn't a bar on the top of my screen anymore to go back and click on 'tools' (or something else). I went into the Panel and did a 'point-to-point anterior restoration' (restore the computer to an earlier date) but it was not good. What can I do to recover things?

    Please see what happened to the menus file, editing and?.

  • Copy the virtual machine files

    Hello

    I would like to know if I had to copy a virtual machine on my personal laptop, what files should I copy? Told me that VMDK files are not enough. That is why I want to what files exactly?

    And also if my application VM and the VM database are 2 different servers, it will work if I copy them and run them on my laptop?

    Thank you.

    If you laptop is isolated from the area, you'll need to local users account on the virtual machine, so I suggest you note the local administrator account and the password and check if this account is activated.

    Just a further point, if the services in the system VMs depends on domain services, for example: If you are using a domain account to run, you need will change this setting to use the local account and give the necessary permission for this local account.

  • Copy the Version Option (file-&gt; workflow-&gt; paper Version)

    Hi all

    I believe that the Version of the copy 'Year' issue FIX - known Limitation have not set in the version 9.3.1 too.

    In addition when a planner or an interactive user performs this activity of version copy by script, source, destination version version and the available entities list shows only the entities to which it has write access. This action replaces the essbase that is defined for this user filters for other dimensions.

    Thank you

    Hello

    The dub version he founded security on the security implemented in the planning, it will be based solely on the safety of members set up on the scenario of size, version, entity.
    If you have custom dimensions and safety of the members which will not take into account.

    He replaces one of the security in essbase and yes it that DATACOPY will be run by the admin account (the account that was used when configuring the essbase data source connection)

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • Windows XP Service Pack 3 copy error: can't copy the file osloader.ntd_

    Whenever I try to install Service Pack 3, I always get an error of copy that it cannot copy the osloader.ntd file. I have no idea what this file is located, or if it's still on my computer.  Any help is appreciated. Thank you.

    WinXP SP1 or SP2 is currently installed?

    Windows XP installed on a Mac & installed Boot Camp 3.0? See http://support.apple.com/kb/HT3841

    ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

Maybe you are looking for