Page tree
Skip to end of metadata
Go to start of metadata

This guide explains how to deal with files and images.

Images can be retrieved from a file or from a URL to be downloaded as a file. It is possible to use the File object to get an image from a file and specify a target file to save an image.

Following objects support working with the File object:

Definitions

SMF.UI.Image

The image property supports assigning strings which look up for certain locations with the file name. The new imageFile property is useful to get and set specific files for the UI Image object.
When the image property is a URL, first the image in the URL is saved to a file in the Downloaded Images directory in applicationTemporaryData. This behavior changes when UI Image is using cached images, then the image will be saved in a different location, in the ImageCache directory of applicationCacheDirectory.

SMF.UI.ImageButton

The same things for SMF.UI.Image applies for the SMF.UI.ImageButton too, for every …image property, an …ImageFile property is defined. As the ImageButton does not have caching for the downloaded images, it never saves the downloaded images under applicationCacheDirectory.

inactiveImage inactiveImageFile
defaultImage → defaultImageFile
highlightedImage → highlightedImageFile

SMF.Bitmap

When an Image object is created, the constructor requires the URL of the image. Instead of the imageURI property, a file reference can be also set using the file property in the constructor.
After creating an image, the file property can be retrieved once the image has been successfully loaded.

Camera

The captured photos with the camera will be saved under the “Camera” sub directory of applicationTemporaryData.

Examples

Image Button example

Assigning a file to an ImageButton as below :

var myImageButton = new SMF.UI.ImageButton({
		top : "75%"
	});
myImageButton.inactiveImageFile = new SMF.IO.File(SMF.IO.applicationResources + "single.png");
myImageButton.defaultImageFile = new SMF.IO.File(SMF.IO.applicationResources + "single.png");
myImageButton.highlightedImageFile = new SMF.IO.File(SMF.IO.applicationResources + "single.png");
page1.add(myImageButton);

Bitmap Object example

Assigning a file to an Bitmap Object as below

var myImageFile = new SMF.IO.File(SMF.IO.applicationResources, "single.png");
var myBitmapObject = new SMF.Bitmap({
		file : myImageFile,
		onSuccess : function (e) {
			alert("Image successfuly loaded: " + e.imageURI);
		},
		onError : function (e) {
			alert(e.message);
		}
	});

Camera example

SMF.Multimedia.startCamera({
    cameraType : SMF.Multimedia.CameraType.REAR, 
    resolution : SMF.Multimedia.Resolution.LARGE,
	autoFocus : true,
	onStart : function () {}, //do nothing
	onCapture : function (e) {
		var photoFile = new SMF.IO.File(e.photoUri); //the full URI is given
		var destination = SMF.IO.applicationDataDirectory + SMF.IO.pathSeparator + photoFile.name;
		var targetFile = new SMF.IO.File(destination);
		if (!targetFile.exists) {
			img.image = targetFile;
			if (photoFile.move(destination)) { //if moved successfully
				alert(photoFile.path);
			}
			else{
				alert("not copied");
				alert(photoFile.path);
			}
		}
	},
	onCancel : function () {}, //do nothing
	onFailure : function () {}
	//do nothing
});

For detailed camera guide please check Camera Usage