Picture editor

Invoking the Picture editor card

Here are the invocation attributes you use to invoke the Picture editor card:

Attribute Value
Target ID

sys.pictureeditor.cardeditor

Action

bb.action.EDIT

URI file:///path/to/content.jpg

Configuring the size of the output image

Parameters Value Example
size

WIDTHxHEIGHT

800x600
upScale

true or false

QString upScale= "false";

You can configure the size of the output image by using the size and the upScale parameters. The size parameter allows you to specify the dimensions of the output image in pixels while the upScale parameter identifies whether the output image is scaled to that specified size or not. The upScale parameter is only valid if you first define a size for your output image. In addition, true is the default value for the upScale parameter.

Depending on how you use these two parameters, you will have one of the three outcomes mentioned below.

Output image size not specified

In this case, size and upScale parameters are not used. This allows the user to crop the image to any size or aspect ratio. On opening, the Picture editor's filter tab opens by default for this case. This use case is demonstrated in the Pictures app of the BlackBerry 10 OS.

Specifying an exact output image size

To specify an exact size for the output image, you must specify a value for the size parameter and set the upScale parameter to true. The value for the upScale parameter can also be omitted since true is the default value.

In this case, the size of the output image is exactly the same as specified by the size parameter. On opening, the Picture editor's transform tab opens by default for this case. The output image is cropped to the same aspect ratio as the size. This also means that the user will not be able to change the aspect ratio of the output image as the buttons to change the aspect ratios are disabled in the Picture editor.

When saving the output image, if the size of the edited image is different from the specified size, the output image is automatically scaled to the specified size. This use case is demonstrated in the Contacts app of the BlackBerry 10 OS.

Specifying a maximum limit for the output image size

To specify a maximum limit for the size of the output image, you must specify a value for the size parameter and set the upScale parameter to false.

In this case, the size of the output image can be smaller but never exceed the size specified in the size parameter. On opening, the Picture editor's transform tab opens by default for this case. The output image is cropped to the same aspect ratio as the size. This also means that the user will not be able to change the aspect ratio of the output image as the buttons to change the aspect ratios are disabled in the Picture editor.

When saving the output image, if the size of the edited image is larger than the size parameter specification, it is automatically downscaled to the specified size. However, if the size of the edited image is smaller than the size parameter specification, the output image size remains the same. This use case is demonstrated in the BBM app of the BlackBerry 10 OS.

The code sample below shows how you can invoke a Picture editor card in normal mode, fixed mode, and set as wallpaper mode. You must also link against the PpsObject class by adding the following line to your project's .pro file:

LIBS += -lbb

//Using PictureHeaderLauncher.h header file

#ifndef PICTUREEDITORLAUNCHER_H_
#define PICTUREEDITORLAUNCHER_H_
 
#include <QObject>
#include <bb/system/InvokeManager>
#include <bb/system/InvokeTargetReply.hpp>
#include <bb/system/CardDoneMessage.hpp>
 
class PictureEditorLauncher : public QObject {
    Q_OBJECT
public:
    PictureEditorLauncher(QObject* pParent = NULL);
    virtual ~PictureEditorLauncher();
 
    Q_INVOKABLE void doLaunch
    (const QString &app, const QString &msg, 
    const QString &sizeString, bool upScale, bool delTmpFile);
 
public slots:
    void childCardDone
    (const bb::system::CardDoneMessage& cardDoneMessage);
 
    void invokeRequestFinished();
 
private:
    bool mDeleteTmpFile;
    bb::system::InvokeManager* m_invokeManager;
    bb::system::InvokeTargetReply* m_targetReply;
};
 
#endif /* PICTUREEDITORLAUNCHER_H_ */
 
Source file: PictureEditorLauncher.cpp
 
#include "PictureEditorLauncher.h"
 
#include <bb/system/SystemToast>
#include <bb/system/InvokeRequest>
#include <bb/system/InvokeReplyError>
#include <bb/PpsObject>
 
using namespace bb::system;

PictureEditorLauncher::PictureEditorLauncher(QObject* pParent)
: QObject(pParent),
  mDeleteTmpFile(true),
  m_invokeManager(0),
  m_targetReply(0)
{
    m_invokeManager = new InvokeManager();
    QObject::connect(m_invokeManager, 
    SIGNAL(childCardDone(const bb::system::CardDoneMessage&)), 
    this, SLOT(childCardDone
    (const bb::system::CardDoneMessage&)));
}

PictureEditorLauncher::~PictureEditorLauncher()
{
}

void PictureEditorLauncher::childCardDone
(const bb::system::CardDoneMessage& cardDoneMessage)
{
...    
}

/**
* mode can be normal, fixedsize, or setwallpaper
* filePath represents the path to the file
*
*/

void PictureEditorLauncher::doLaunch(const QString &mode, 
const QString &filePath, 
const QString &sizeString, bool upScale, bool delTmpFile)
{
    mDeleteTmpFile = delTmpFile;

    // card request
    InvokeRequest cardRequest;
    cardRequest.setAction("bb.action.EDIT");
    cardRequest.setFileTransferMode
    (bb::system::FileTransferMode::CopyReadOnly);

    if(mode == "normal")
    {
        QByteArray data;
        data = "Normal";
        cardRequest.setData(data);
        cardRequest.setTarget("sys.pictureeditor.cardeditor");
    }
    else if (mode == "fixedsize" || mode == "setwallpaper")
    {
        qDebug() << "Launch Picture Editor in fixedsize mode";
        QVariantMap data = QVariantMap();
        data["size"] = sizeString;
        QString upScaleString = QString(upScale);
        data["upScale"] = upScaleString;
        bool ok;
        QByteArray encData = bb::PpsObject::encode(data, &ok);
        cardRequest.setData(encData);
        cardRequest.setTarget("sys.pictureeditor.cardeditor");
        // "wallpaper" mode
        if (mode == "setwallpaper") {
          cardRequest.setTarget
          ("sys.pictureeditor.setaswallpaper");
          cardRequest.setAction("bb.action.SET");
        }
    }
    else
    {
        cardRequest.setTarget("sys.pictureeditor.app");
    }

    cardRequest.setUri(QUrl::fromLocalFile(filePath));

    qDebug() << "Launching pictureEditor:" 
    << cardRequest.uri().toString();
    qDebug() << "Launching target:" << cardRequest.target();
    m_targetReply = m_invokeManager->invoke(cardRequest);

    QObject::connect(m_targetReply, SIGNAL(finished()), 
    this, SLOT(invokeRequestFinished()));
}

void PictureEditorLauncher::invokeRequestFinished()
{
...
}

Here's how you can launch the Picture editor card:

pLauncher = new PictureEditorLauncher(this);
pLauncher->doLaunch("normal", 
"/accounts/1000/shared/camera/IMG_20131103_191915.jpg", 
"200x400", false, true);

Last modified: 2013-12-21

comments powered by Disqus