ImageConverter

Since: BlackBerry 10.0.0

#include <bb/utility/ImageConverter>

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

Encodes and decodes images to and from different sources in various formats.

Images may be stored in memory or stored in local files. Images formats are denoted using mime types, such as "image/png", "image/jpeg", and so on, or by the file extension of a given path, such as ".png", ".jpg", and so on.

The list of supported formats depends on the codecs that are installed on a device at a particular time. You can use img_codec_list(), which is part of the C library, to get a complete list of installed codecs. For more information on C APIs, see http://developer.blackberry.com/native/reference/bb10.

Here's how to use the ImageConverter class to decode a PNG image:

 ImageData image = ImageConverter::decode("foo.png");

In addition to decoding images, this class also contains functionality for encoding images into a specific format (PNG, JPEG, and so on).


Overview

Public Functions Index

Static Public Functions Index

ImageDatadecode (const QUrl &fileUrl, PixelFormat::Type format=bb::PixelFormat::RGBA_Premultiplied)
ImageDatadecode (const QByteArray &encodedData, PixelFormat::Type format=bb::PixelFormat::RGBA_Premultiplied)
QByteArrayencode (const QString &mimeType, const ImageData &imageData, int quality=75)
boolencode (const QUrl &fileUrl, const ImageData &imageData, int quality=75)

Public Functions

ImageConverter ()

Creates a new instance of the ImageConverter class.

Since:

BlackBerry 10.0.0

~ImageConverter ()

Destructor.

Since:

BlackBerry 10.0.0

Static Public Functions

ImageData decode (

Creates an ImageData object from an image file.

Parameters
fileUrl

The location of the image file. Supports "asset:///" and "file:///" URLs as well as normal file paths.

format

The pixel format of the resultant ImageData. If not specified, the default pixel format is PixelFormat::RGBA_Premultiplied.

Return:

The newly created ImageData. If the image could not be loaded, ImageData::isValid() will return false.

Since:

BlackBerry 10.0.0

ImageData decode (

Creates an ImageData object from encoded image data.

The encoded data can be in any number of formats (PNG, JPEG, and so on).

Parameters
encodedData

The encoded image data (PNG, JPEG, and so on). The encoded format is determined by examining the encodedData.

format

The pixel format of the resultant ImageData. If not specified, the default pixel format is PixelFormat::RGBA_Premultiplied.

Return:

The newly created ImageData. If the file could not be loaded, ImageData::isValid() will return false.

Since:

BlackBerry 10.0.0

QByteArray encode (

Converts an image into an encoded format (PNG, JPEG, and so on).

Parameters
mimeType

The format that the image will be encoded into (for example, "image/png", "image/jpeg", and so on).

imageData

The image to be encoded.

quality

The quality of the encoding. Valid values are from 0 to 100. This parameter is used only by codecs that support it. If not specified, the default quality value is 75.

Return:

The encoded image data. If the image could not be encoded, the returned QByteArray will be empty.

Since:

BlackBerry 10.0.0

bool encode (

Converts an image into an encoded format (PNG, JPEG, and so on).

Parameters
fileUrl

The location to save the image. The image format (PNG, JPEG, and so on) is determined by file extension. Supports the "asset:///foo.png" and "file:///path/to/foo.png" formats, standard absolute paths, and relative paths like "folder/foo.png".

imageData

The image to be encoded.

quality

The quality of the encoding. Valid values are from 0 to 100. This parameter is used only by codecs that support it. If not specified, the default quality value is 75.

Return:

true if the image was encoded successfully, false otherwise.

Since:

BlackBerry 10.0.0

Last modified: 2014-09-30



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus