You are here: Creating a Camera Using a Constructor: kony.ui.Camera

Camera Widget

Camera widget allows you to capture pictures and videos using native Camera or using customized Camera (overlay Camera).

Some real-world scenarios when you can use Camera widget are as follows:

The key features of the Camera widget are as follows:

Compression: You can compress the image captured from the Camera widget to a manageable size. This image can then be either stored in the device or in a server.

RawBytes and base64: You can store the images captured from the Camera widget by using base64 string and raw bytes. These strings can then be assigned to an Image widget to view it in the application or be stored in a server for later use.

Back and Front Camera Compatibility: You can utilize both the front and back cameras of a mobile device by using a Camera widget.

Overlay: Overlay is a transparent form that is assigned to a Camera widget for customizing the camera screen.

Video Capturing: The Camera widget also has the capability to capture videos. You can change the mode of the camera to Video, and then capture the required video.

Responsive Web Support

Camera widget is supported in Responsive Web/ Desktop Web platforms from Kony Visualizer V8 SP4 FP 20 onwards. You can create Camera widget for Responsive Web/ Desktop Web platforms through code only.

You can now capture images and videos by using the Camera widget with a web browser.

Take a Picture by using Front and Rear Cameras

Record a Video by Using Front and Rear Cameras

The following table displays the browser support for the various methods in Camera widget.

Browser Support openCamera closeCamera takePicture startVideoCapture stopVideoCapture
Chrome(74.0)
Firefox (66.0)
Edge (42.17134)
IE (11.7)
Opera (60)
Mobile FireFox(66.0.2)
Mobile Chrome(74.0) (only using https)
Safari(11.12)
Safari iOS Mobile (only using https)
Chrome for MAC & iOS

 

Widgets are normally added to your Kony application by using Kony Visualizer, but they can also be added through code. For general information on using widgets in Kony Visualizer, refer Designing an Application in the Kony Visualizer User Guide.

For general information on the Camera widget see the Camera topic in the Kony Visualizer User Guide.

Note: From Kony VisualizerV8 SP4 onwards, the Camera widget's data for a Kony Quantum App Viewer child app is stored in child app data and not under the parent app. This feature is applicable for iOS, Windows, and Android platforms.

For a more hands-on approach on the functionality of Camera widget, import and preview the Camera Feature sample app by using Kony Visualizer.

The Camera widget capabilities can be broadly categorized into the following:

Layout

Events Description
doLayout Invoked for every widget when the widget position and dimensions are computed.
 
PropertiesDescription
bottom Determines the bottom edge of the widget and is measured from the bottom bounds of the parent container.
centerX Determines the center of a widget measured from the left bounds of the parent container.
centerY Determines the center of a widget measured from the top bounds of the parent container.
contentAlignment Specifies the alignment of the text for a widget with respect to its boundaries.
height It determines the height of the widget and measured along the y-axis.
leftDetermines the lower left corner edge of the widget and is measured from the left bounds of the parent container.
maxHeight Specifies the maximum height of the widget and is applicable only when the height property is not specified.
maxWidth Specifies the maximum width of the widget and is applicable only when the width property is not specified.
minHeight Specifies the minimum height of the widget and is applicable only when the height property is not specified.
minWidth Specifies the minimum width of the widget and is applicable only when the width property is not specified.
right Determines the lower right corner of the widget and is measured from the right bounds of the parent container.
topDetermines the top edge of the widget and measured from the top bounds of the parent container.
width Determines the width of the widget and is measured along the x-axis.
zIndex Specifies the stack order of a widget.

UI Appearance

PropertiesDescription
backgroundColorSpecifies the background color of the widget in hex format.
focusSkin Specifies the look and feel of the widget when in focus.
hoverSkin Specifies the look and feel of a widget when the cursor hovers on the widget.
posterSpecifies the placeholder image for Camera widget when the device camera is not open.
opacity Specifies the opacity of the widget.
skin

Animations

MethodsDescription
animateApplies an animation to the widget.

Capturing Features

MethodsDescription
closeCameraAllows you to close the camera.
getSupportedCameraSourcesReturns an array of supported camera sources.
openCameraOpens the camera preview.
startVideoCaptureAllows you to capture a video that will end as configured in the videoDuration property.
stopVideoCaptureAllows you to stop a video that is being captured using startVideoCapture method.
takePictureAllows you to capture the picture when the camera is in preview mode.
 
PropertiesDescription
cameraOptionsSpecifies the camera options that can be used on a form.
cameraSourceSpecifies the source of the camera, either front or rear.
captureOrientationsSpecifies the orientation of the captured image.
captureModeSpecifies the capture mode of the camera.
compressionLevelSpecifies the compression level or picture quality with which the captured image must be stored.
enableOverlayThe camera is launched with capability of over-lay a Form UI over the camera view.
enablePhotoCropFeatureEnables you to crop the captured image.
enableZoomSet this property as true to enable pinch to zoom of the camera preview in the overlay mode.
focusMode Specifies the focus mode for the camera and is respected when the enableOverlay is set to true.
imageFormatSpecifies if the image must be stored as a PNG (Portable Network Graphics) or a JPEG (Joint Photographic Experts Group) image.
maxSideOfTheImageSpecifies the width of the camera picture/image.
nativeUserInterfaceSpecifies if the camera must have the native interface on camera view (an interface with the default platform controls for camera) or the user interface with custom options.
overlayConfigSpecifies the overlay configuration parameters for overlaying a form.
scaleFactor Specifies the ratio by which the captured image is reduced.
supportedVideoQualityLevelsReturns an array of possible quality levels for the given device for the configured camera source.
videoStabilizationEnables you to reduce the shaking of the camera while shooting a video.
videoFormat Specifies the video format of the captured video.
videoDuration Specifies the length of the captured video in seconds.
videoQualityLevelSpecifies the quality of the video.
 
EventsDescription
onCapture Invoked when the user captures a picture.
onCaptureFailed Invoked when the user has tapped on Don't Allow over permission alert and also when camera privacy is turned off under iPhone settings.
onFailure Invoked when an error occurs using a camera widget.
onImageSaveFailedInvoked when the user has performed some action over permission alert and also when image cannot be saved to photo album or due to data save error.

Data Mangement

MethodsDescription
clone When this method is used on a container widget, then all the widgets inside the container are cloned.

3D Touch

MethodsDescription
registerForPeekandPop Registers a widget to enable 3D Touch peek and pop gestures.
setOnPeek Sets and overrides the existing onPeekCallback for the widget.
setOnPop Overrides the existing onPopCallback for the widget.
unregisterForPeekandPopUnregisters a widget from 3D Touch peek and pop gestures.

User Input Handling

EventsDescription
onTouchEnd Invoked by the platform when the user touch is released from the touch surface.
onTouchMoveInvoked by the platform when the touch moves on the touch surface continuously until movement ends.
onTouchStart Invoked by the platform when the user touches the touch surface.
 
MethodsDescription
addGestureRecognizer Allows you to set a gesture recognizer for a specified gesture for a specified widget.
removeGestureRecognizer Allows you to remove a child widget from a parent widget.
setGestureRecognizerAllows you to set a gesture recognizer for a specified gesture for a specified widget.

Enabling RTL

PropertiesDescription
retainContentAlignmentHelps to retain the content alignment of the widget while applying RTL.
retainFlexPositionPropertiesHelps to retain the left, right and padding properties while applying RTL.
retainFlowHorizontalAlignmentEnables you to change the horizontal flow of the widget from left to right.

Miscellaneous

MethodsDescription
getBadge Enables you to read the badge value (if any) attached to the specified widget.
setBadgeEnables you to set the badge value to the given widget at the upper, right corner of the widget.
 
PropertiesDescription
accessMode Specifies how the captured image must be stored.
base64 Returns the base64-encoded string of the image raw bytes.
cursorTypeSpecifies the type of the mouse pointer used.
rawBytes Specifies the rawbytes representing an Image (usually the image captured from the camera) that can be used as a background for the Camera.

Configurations common to all widgets

MethodsDescription
convertPointFromWidgetAllows you to convert the coordinate system from a widget to a point (receiver's coordinate system).
convertPointToWidgetAllows you to convert the coordinate system from a widget to a point (receiver's coordinate system).
removeFromParentAllows you to remove a child widget from a parent widget.
setEnabledSpecifies the widget that must be enabled or disabled.
setFocusSpecifies the widget on which there must be focus.
setVisibilityUse this method to set the visibility of the widget.
 
PropertiesDescription
accessibilityConfig Enables you to control accessibility behavior and alternative text for the widget.
enableCache Enables you to improve the performance of Positional Dimension Animations.
id id is a unique identifier of the Camera Widget consisting of alphanumeric characters.
info A custom JSObject with the key-value pairs that a developer can use to store the context with the widget.
isVisibleControls the visibility of a widget on the form.
parentHelps you access the parent of the widget.
 

Camera Widget Basics

If you select the Camera widget, the phone camera is invoked to capture an image (which you can choose to accept or discard) and is stored as a PNG (Portable Network Graphics) image by default (JPEG in BlackBerry platform) with the original size.

Note: Camera widget is not supported for SPA platform.

The following are few examples where you can use a Camera widget:

Creating a Camera Using a Constructor: kony.ui.Camera


var mycamera = new kony.ui.Camera(basicConf, layoutConf, pspConf);

Note: The configuration properties should be passed only in the respective configuration objects otherwise they are ignored.

Example

//Defining the properties for a Camera.
var camBasic = {
    id: "camera1",
    skin: "camSkin",
    focusSkin: "camFSkin",
    text: "Camera",
    isVisible: true
};

var camLayout = {
    containerWeight: 100,
    padding: [5, 5, 5, 5],
    margin: [5, 5, 5, 5],
    paddingInPixel: true,
    marginInPixel: true,
    hExpand: true,
    vExpand: true
};

var camPSP = {
    enableOverlay: true
};

//Creating the Camera.
var camera1 = new kony.ui.Camera(camBasic, camLayout, camPSP);

//Reading enableOverlay of Camera.
alert("Camera enableOverlay::" + camera1.enableOverlay);

Note: For optimization, the raw bytes property can be read only once. Once it is read, the platform releases the handle. The camera image handle is provided to the action handler and if the action handler does not store the image handle, the image cannot be retrieved from the widget (the camera widget does not have the getImageHandle method).

To delete the rawbytes, use the releaseRawBytes method.

Common Issues

The following are the issues to avoid for a camera:

Important Considerations

The following are the important considerations of the camera widget across all platforms and individual platforms:

Limitations of Camera widget in video capture mode:

premCopyright © 2012 Kony, Inc. All rights reserved.
premCopyright © 2012 Kony, Inc. All rights reserved.