Tour Preview

Find the Best Demos and Examples

Check out this quick tour to find the best demos and examples for you, and to see how the Felgo SDK can help you to develop your next app or game!


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

Import Statement: import Felgo 3.0
Since: Felgo 2.18.1


Detailed Description

The HttpImageUtils only work in conjunction with the HttpRequest item of the Felgo DuperAgent integration. It is available as a singleton item and usable from all QML components that import Felgo via import Felgo 3.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);;

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);;

    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.

  • 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:

       .setScaledSize(200, 200)
         transcode: {
           format: "jpg",
           quality: 50

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

Method Documentation

var createReader(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.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded