HttpImageUtils

Provides functionality for scaling and cropping an image file before uploading it with HttpRequest. More...

Import Statement: import VPlayApps 1.0
Since: V-Play 2.18.1

Methods

Detailed Description

The HttpImageUtils only work in conjunction with the HttpRequest item of the V-Play DuperAgent integration. It is available as a singleton item and usable from all QML components that import V-Play via import VPlayApps 1.0.

When uploading images using HttpRequest, the HttpImageUtils allow to crop, scale and transcode image files before the upload.

Example Usage

The first step is to create a reader for your image. The reader allows to get and set configuration properties, before calling read to load the image with the given settings.

For example to clip the image, you can use the setClipRect function of the reader:

 var reader = HttpImageUtils.createReader(imagePath);
 reader.setClipRect(0, 0, 200, 200);
 reader.read();

The read function reads and decodes the image into memory based on the previously configured settings. You can pass the returned object of read to the attach function of a request created with HttpRequest.

HttpImageUtils Reader API

The reader object retrieved from createReader() supports the following methods:

  • var size() - Returns an object with the width and height properties of the image without actually decoding the image.
  • int filesize() - Returns the filesize (in bytes) of the encoded image.
  • var setScaledSize(int width, int height, int fitMode)

    Sets the desired scaled size for the image when it is decoded. Depending on the image format, some decoders can do this efficiently without having to decode the full image first and then downscale.

     var reader = HttpImageUtils.createReader(imagePath);
     reader.setScaledSize(200, 200, Image.PreserveAspectCrop);
     reader.read();

    For the fitMode, the supported values are Image.Stretch, Image.PreserveAspectFit and Image.PreserveAspectCrop.

  • var setClipRect(int x, int y, int width, int height) - Sets a clipping rectangle for the image reader.
  • var setScaledClipRect(int x, int y, int width, int height) - Sets a scaled clip rect for the image reader.
  • var setAutoTransform(bool enabled)

    Rotates the image if the metadata for the image indicates that it should.

     HttpImageUtils.createReader(imagePath)
       .setAutoTransform(true)
       .read();
  • var read(var options)

    Reads and decodes the image into memory. This function can take optional object of options, which can transcode the image to a different format and quality:

     HttpImageUtils.createReader(imagePath)
       .setScaledSize(200, 200)
       .read({
         transcode: {
           format: "jpg",
           quality: 50
         }
       });

    The function returns an image object you can attach to a request created with HttpRequest.

Method Documentation

var createReader(string filepath)

This function accepts a file path to an image or to a base64 encoded data uri containing image data and returns an image reader. The image is not decoded at this point, only the reader is created.


Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support