Screenshot

Since: BlackBerry 10.2.0

#include <bb/system/Screenshot>

To link against this class, add the following line to your .pro file: LIBS += -lbbsystem

Allows an application to capture the contents of the display or the application window and save it to a file.

When capturing the display, the image is saved to the camera roll (a sequentially numbered image available in the Pictures application, just like taking a picture with the camera) in any one of the formats specified by ScreenshotFormat.


Overview

Public Functions Index

Screenshot (QObject *parent=0)
virtual ~Screenshot ()
Q_INVOKABLE QStringcaptureDisplay ()
Q_INVOKABLE QStringcaptureDisplay (const QUrl &filePath)
Q_INVOKABLE QStringcaptureDisplay (bb::system::ScreenshotFormat::Type format)
Q_INVOKABLE QStringcaptureWindow (const QUrl &filename, screen_window_t window)
Q_INVOKABLE bb::system::ScreenshotError::Typeerror () const

Public Functions

Screenshot (

Creates a new Screenshot object.

Allows applications to capture the display or an application window to a file.

Parameters
parent

If not 0, the supplied parent will be responsible for deleting this instance.

Since:

BlackBerry 10.2.0

virtual~Screenshot ()

Destructor.

Since:

BlackBerry 10.2.0

Q_INVOKABLE QString captureDisplay ()

Captures the display to the camera roll.

Captures the display to a file with an autogenerated name in PNG format.

Return:

The absolute path to the file containing the image that was captured. If an error occurs, the method returns an empty string and the error method must be called to determine the reason for the failure.

Capturing screenshot in C++:
bb::system::Screenshot screenshot;
QString filename = screenshot.captureDisplay();
if (filename.isEmpty()) {
    // Something went wrong
    bb::system::ScreenshotResult::Type error = screenshot.error();
}
Capturing screenshot in QML:
import bb.cascades 1.0
import bb.system 1.2

Page {
    attachedObjects: [
        Screenshot {
            id: screenshot
        }
    ]
    
    content: Container {        
        Label {
            id: filenameLabel
        }
        Button {
            id: captureButton
            text: "Capture"
            onClicked: {
                filenameLabel.text = screenshot.captureDisplay();
            }
        }
    }
    
}
Permissions:

The application must have the use_camera_desktop and access_shared permissions to use this feature.

Since:

BlackBerry 10.2.0

Q_INVOKABLE QString captureDisplay (
  • const QUrl &filePath)

Captures the display to the camera roll.

Captures the display to a file with the supplied name. The format of the image is inferred from the filename. The filePath can be supplied as an absolute filename, or using a schema, such as "file:data/screenshot.png".

Parameters
filePath

The target filename to which the captured image will be written. The extension of this filename will determine the image format of the screen capture.

Return:

The absolute path to the file containing the image that was captured. If an error occurs, the method returns an empty string and the error method must be called to determine the reason for the failure.

Capturing screenshot in C++:
bb::system::Screenshot screenshot;
QString filename = screenshot.captureDisplay( "file:data/screenshot.png" );
if (filename.isEmpty()) {
    // Something went wrong
    bb::system::ScreenshotResult::Type error = screenshot.error();
}
Capturing screenshot in QML:
import bb.cascades 1.0
import bb.system 1.2

Page {
    attachedObjects: [
        Screenshot {
            id: screenshot
        }
    ]
    
    content: Container {        
        Label {
            id: filenameLabel
        }
        Button {
            id: captureButton
            text: "Capture"
            onClicked: {
                filenameLabel.text = screenshot.captureDisplay( "file:data/screenshot.png" );
            }
        }
    }
    
}
Permissions:

The application must have the use_camera_desktop and access_shared permissions to use this feature.

Since:

BlackBerry 10.2.0

Q_INVOKABLE QString captureDisplay (

Captures the display to the camera roll in the supplied format.

Captures the display to a file with an autogenerated name in the supplied image format. See bb::system::ScreenshotFormat for the list of supported formats.

Parameters
format

The format of the resulting file, such as PNG or JPEG. One of bb::system::ScreenshotFormat.

Return:

The absolute path to the file containing the image that was captured. If an error occurs, the method returns an empty string and the error method must be called to determine the reason for the failure.

Capturing screenshot in C++:
bb::system::Screenshot screenshot;
QString filename = screenshot.captureDisplay( bb::system::ScreenshotFormat::Jpg );
if (filename.isEmpty()) {
    // Something went wrong
    bb::system::ScreenshotResult::Type error = screenshot.error();
}
Capturing screenshot in QML:
import bb.cascades 1.0
import bb.system 1.2

Page {
    attachedObjects: [
        Screenshot {
            id: screenshot
        }
    ]
    
    content: Container {        
        Label {
            id: filenameLabel
        }
        Button {
            id: captureButton
            text: "Capture"
            onClicked: {
                filenameLabel.text = screenshot.captureDisplay( ScreenshotFormat.Jpg );
            }
        }
    }
    
}
Permissions:

The application must have the use_camera_desktop and access_shared permissions to use this feature.

Since:

BlackBerry 10.2.0

Q_INVOKABLE QString captureWindow (
  • const QUrl &filename,
  • screen_window_twindow )

Captures the application window to the supplied filename.

The captured image will be written in the format specified by the filename. (For example, if the filename was "file:data/screenshot.png" the file would be written as a PNG format image.)

Parameters
filename

The path to which the file will be captured.

window

The handle of the application window to be captured.

Return:

The absolute path to the file containing the image that was captured. If an error occurs, the method returns an empty string and the error method must be called to determine the reason for the failure.

Capturing screenshot in C++:
bb::system::Screenshot screenshot;
QString filename = screenshot.captureWindow( "file:data/screenshot.png", Application::instance()->mainWindow()->handle() );
if (filename.isEmpty()) {
    // Something went wrong
    bb::system::ScreenshotResult::Type error = screenshot.error();
}
Capturing screenshot in QML:
import bb.cascades 1.0
import bb.system 1.2

Page {
    attachedObjects: [
        Screenshot {
            id: screenshot
        }
    ]
    
    content: Container {        
        Label {
            id: filenameLabel
        }
        Button {
            id: captureButton
            text: "Capture"
            onClicked: {
                filenameLabel.text = screenshot.captureWindow( "file:data/screenshot.png", Application.mainWindow.handle );
            }
        }
    }
    
}
Since:

BlackBerry 10.2.0

Q_INVOKABLE bb::system::ScreenshotError::Type error ()

Gets the result for the last captureDisplay or captureWindow request.

Return:

The result of the last captureDisplay or captureWindow request. See bb::system::ScreenshotError for a list of possible results.

Since:

BlackBerry 10.2.0

Last modified: 2014-03-13

comments powered by Disqus