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

This guide explains how to use the camera of the device in a project.

Capture

The basic function of a camera is to capture a photo. The Smartface uses native camera components for capturing a photo with the "SMF.Multimedia.startCamera()" method.

Parameters

nametypedescription
cameraTypeIntegerThe camera type can be SMF.Multimedia.CameraType.FRONT or SMF.Multimedia.CameraType.REAR camera.
resolutionIntegerThe resolution can be SMF.Multimedia.Resolution.SMALL, SMF.Multimedia.Resolution.MEDIUM or SMF.Multimedia.Resolution.LARGE.
autoFocusBooleanIt is set true for auto focus.
onStartFunctionCallback function occurs when the camera is started.
onCaptureFunctionCallback function occurs when the camera captures a photo.
onCancelFunctionCallback function occurs when the camera is cancelled.
onFailureFunctionCallback function occurs when there is an error.

Sample

Here is the simple code lines of an application which captures a photo;

SMF.Multimedia.startCamera({
	cameraType : SMF.Multimedia.CameraType.REAR, 
	resolution : SMF.Multimedia.Resolution.LARGE,
	autoFocus : true,
	onStart : function () {}, //do nothing
	onCapture : function (e) {
		alert("path=" + e.photoUri);
	},
	onCancel : function () {}, //do nothing
	onFailure : function () {}
	//do nothing
});

Save

In general use, the captured photos should be saved to the device gallery. The "Device.Media.saveToGallery()" method is used to save an image to the gallery.

Parameters

nametypedescription
itemStringThe item which will be saved to the Device.
nameStringThe name of the item which will be saved to the device.
onSuccessFunctionTriggers if the item successfully added to the device.
onErrorFunctionTriggers if an error occurs while trying to save the item to the device.

Sample

Here is the simple code lines of an application which captures a photo and saves it to the gallery ;

var photoUri = "";
SMF.Multimedia.startCamera(
	cameraType : SMF.Multimedia.CameraType.REAR, 
    resolution : SMF.Multimedia.Resolution.LARGE,
    autoFocus : true,
	function (e) {},
	function (e) {
		photoUri = e.photoUri;
		Device.Media.saveToGallery({
			item : photoUri,
			name : "myPhoto.jpg",
			onSuccess : function (e) {
				alert("The image is saved to the gallery.");
			},
			onError : function (e) {
				alert("error: " + e.message);
			}
		});
	},
	function (e) {},
	function (e) {}
);

Crop

In the mobile applications, the captured images are generally more useful when they are cropped. The Smartface let developers to use the native crop components. The "SMF.UI.cropImage()" method is used to open the native crop components.

Parameters

nametypedescription
imageUriStringThe Uri of the image to be cropped. It can be an SMF.Bitmap object, SMF.File object or a string.
optionsObject

The aspect and output parameters. They can be:

  • aspectX: The X value of the aspect.
  • aspectY: The Y value of the aspect.
  • outputX: The width of the output image. [Android only]
  • outputY: The height of the output image. [Android only]
onSuccessFunctionTriggers after the image is cropped successfully. It returns the new image with “e.imageUri”. The filename pattern will be “crop_[timestamp].[extension]
onErrorFunctionTriggers if an error happens. The “e.message“ returns the error
onCancelFunctionTriggers if the user cancels the crop screen

Sample

Here is the simple code lines of an application which captures a photo , crops the photo and saves it to the gallery ;

var photoUri = "";
SMF.Multimedia.startCamera(
	cameraType : SMF.Multimedia.CameraType.REAR, 
    resolution : SMF.Multimedia.Resolution.LARGE,
    autoFocus : true,
	function (e) {},
	function (e) {
		photoUri = e.photoUri;
		SMF.UI.cropImage({
			imageUri : photoUri,
			options : {
				aspectX : 1,
				aspectY : 1,
				outputX : 500,
				outputY : 500
			},
			onSuccess : function (e) {
				// e.imageUri
				// e.width
				// e.height
				Device.Media.saveToGallery({
					item : e.imageUri,
					onSuccess : function (e) {
						alert("The image is saved to the gallery.");
					},
					onError : function (e) {
						alert("error: " + e.message);
					}
				});
			},
			onError : function (e) {
				// e.message
			},
			onCancel : function (e) {
				alert("The camera is cancelled");
			}
		});
	}, 
	function (e) {},
	function (e) {}
);