image Object
The image Object, not to be confused with the Image Widget, is a JavaScript object that retrieves images as raw bytes. It provides the following API element:
Methods
The image Object contains the following methods.
compress Method
Compresses an image by the specified compression ratio.
Syntax
<<imageObject>>.compress(compressionRatio)
Input Parameters
Parameter | Description |
---|---|
compressionRatio | A floating point value that specifies the amount of compression to use. |
Example
var imgObj = voltmx.image.createImage(rawBytes);
imgObj.compress(0.8);
Return Values
None.
Remarks
This method compresses the Image object's bitmap using the JPEG compression algorithm. The floating point value in the compressionRatio parameter must be in the range of 0.0<=compressionRatio<=1.0. If compressionRatio is 0.0, this method uses the minimum amount of compression. A value of 1.0 specifies the maximum amount of compression. Values outside the allowed range will be clamped to the nearest valid value. The compression data size that this method produces will vary depending on the hardware platform.
Availability
Available on iOS and Android.
cropToRect Method
This method crops the bitmap contained by the Image object to the size of the input rectangle.
Syntax
cropToRect(
array)
Input Parameters
Parameter | Description |
---|---|
array | An array of integers specifying the cropping rectangle in the order (x,y,width,height). |
Example
var imgObj = voltmx.image.createImage(rawBytes);
imgObj.cropToRect([0, 0, 720, 720]);
Return Values
None.
Remarks
This method crops the current Image object's bitmap to the size of the rectangle specified in the array parameter, altering the bitmap in the process.
If there is no intersection between the Image object's bitmap and the rectangle in the array parameter, then no cropping is performed.
Availability
Available on iOS and Android.
findImageInGallery Method
Searches for and retrieves and image in the device's gallery of pictures.
Note:For Android below permissions are required in IRIS project setting -> Native-> Android Mobile/Tablet -> Tags (Child tag entries under < manifest > tag) depending on the target version
If target version is 33 and above below media permission must be added.
- < uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
If target version is 34 and above below permission must be added along with other media permissions.- < uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED"/>
For more information about Android 14 behavioral change click here, also for understanding other media permissions please refer Android 13.
Syntax
findImageInGallery(
config)
Input Parameters
Parameter | Description |
---|---|
config | A JavaScript object containing the information needed to search for the image. This object holds the following key-value pairs.albumName: An optional string that specifies the album to search. Not used on iOS. imageName: A string that holds the file name (including the extension) of the image file to search for. |
Example
var imgObj = voltmx.image.createImage("src.png");
imgObj.writeToGallery();
var uniqueImgIdentifier;
function onSuccess(uniqueIdentifier) {
uniqueImgIdentifier = uniqueIdentifier;
}
config = {
ImageName: uniqueImgIdentifier
};
var rawBytesObj = findImageInGallery(config);
Return Values
Returns an object of type voltmx.types.RawBytes that contains the RawBytes image data if the file exists, or null
if the file is not found.
Exceptions
Value | Description |
---|---|
100 | Either albumName or imageName was not of type String. |
getImageAsRawBytes Method
Retrieves the image height as an integer.
Syntax
getImageAsRawBytes(
encodingFormat)
Input Parameters
Parameter | Description |
---|---|
encodingFormat | A constant from the Image Format Constants in the voltmx.image namespace that specifies the format of the bitmap image. |
Example
var imgobj = voltmx.image.createimage(rawbytes);
var imgobj = voltmx.image.createimage(form1.camera1.rawbytes);
imgobj.writetomediagallery();
var uniqueimgidentifier;
function onsuccess(uniqueidentifier) {
uniqueimgidentifier = uniqueidentifier;
}
config = {
imagename: uniqueimgidentifier
};
var rawbytesobj = voltmx.image.findimageingallery(config);
form1.img1.rawbytes = rawbytesobj;
Return Values
The Image object's bitmap in RawBytes format if an image format is specified. If not, this method returns the RawBytes data in a platform-specific formats.
Availability
Available on iOS and Android.
getImageHeight Method
Retrieves the image height as an integer.
Syntax
getImageHeight();
Example
var imgObj = voltmx.image.createImage(rawBytes);
var imgHeight = imgObj.getImageHeight();
voltmx.print("Image height is:" + imgHeight);
form1.img1.rawbytes = rawbytesobj;
Input Parameters
None.
Return Values
An integer that specifies the height of the Image.
Availability
Available on iOS and Android.
getImageWidth Method
Retrieves the image width as an integer.
Syntax
getImageWidth();
Example
var imgObj = voltmx.image.createImage(rawBytes);
var imgWidth = imgObj.getImageWidth();
voltmx.print("Image width is:" + imgWidth);
Input Parameters
None.
Return Values
An integer that specifies the object of the Image.
Availability
Available on iOS and Android.
releaseImage Method
Removes the internal image from the image object.
Syntax
<<imageObject>>.releaseImage()
Example
var imgObj = voltmx.image.createImage(rawB);
imgObj.releaseImage();
Input Parameters
None.
Return Values
None.
Availability
Available on iOS.
rotate Method
Rotates an imageObject either in a clockwise or counter-clockwise manner, depending on the specified rotation degree. In addition, you can use this API on Windows platform to crop the edges of the rotated image based on the provided cropImage value.
Syntax
<<imageObject>>.rotate(degree, cropImage)
Input Parameters
Parameter | Description |
---|---|
degree [Number] - Mandatory | The degree by which the imageObject is to be rotated. You can specify any number for the degree parameter: positive or negative. For positive number: rotation occurs in a clockwise manner. For negative number: rotation occurs in a counter-clockwise manner. For example, rotate(90) ,rotate(-90) , rotate(355.5), and rotate(367.5). |
cropImage [Boolean] - Optional | If cropImage is true, the rotated imageObject is cropped at the edges; otherwise, the imageObject is not cropped. The default value for cropImage is false.For example, rotate(45, true) and rotate(-145, false). |
Example
//Rotate image without crop filter applied
var imageObject = voltmx.image.createImage("Image.png");
imageObject.rotate(45);
//Rotate image without crop filter applied
var imageObject = voltmx.image.createImage("Image.png");
imageObject.rotate(45, true);
Return Values
None.
Remarks
- The rotate API does not return a new rotated image, instead it rotates the received image.
Limitations
- The cropImage parameter is applicable only for the Windows platform.
Platform Availability
- iOS
- Android
- Windows
scale Method
Scales the bitmap in the current Image object to a larger or smaller size.
Syntax
scale(scaleFactor)
Input Parameters
Parameter | Description |
---|---|
scaleFactor | A floating point number that is used to scale the bitmap to a larger or smaller size. |
Example
var imgObj = voltmx.image.createImage(rawB);
imgObj.scale(0.4);
Return Values
None.
Remarks
The floating point number in the scaleFactor parameter cannot be less than zero. If it is in the range 0.0<=scaleFactor<1.0, the bitmap size will be reduced. Depending on the hardware and the size of the bitmap, distortion or blurring of the image can occur when it is reduced. If scaleFactor equals 1, this method does nothing.
When your app sets scaleFactor to a value greater than 1.0, the size of the bitmap increases. Values greater than 2.0 may result into memory warnings on some platforms. The resultant image quality may differ on platforms due to interpolation algorithms used.
Availability
Available on iOS and Android.
writeToMediaGallery Method
Writes an image to device's media gallery.
Note:For Android below permissions are required in IRIS project setting -> Native-> Android Mobile/Tablet -> Tags (Child tag entries under < manifest > tag) depending on the target version
If target version is 33 and above below media permission must be added.
- < uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
If target version is 34 and above below permission must be added along with other media permissions.- < uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED"/>
For more information about Android 14 behavioral change click here, also for understanding other media permissions please refer Android 13.
Syntax
writeToMediaGallery(
config)
<