语言

Menu
Sites
Language
How to Open a camera

I want to open a camera using  onclick event and  take a image then show in own application home page....
 

响应

6 回复
Marco Buettner
takeAPicture: function()
    {
        var appId = null,
            appControlReplyCallback = null,
            appControl = null;
 
        appId = 'tizen.camera'; 
        appControl = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/create_content", null, "image/jpeg", null);
 
        appControlReplyCallback =
        {
            onsuccess: function(data)
            {
                var picLink = "";

                if ($.mobile.popup.active)
                {
                    $.mobile.popup.active.close();
                }
 
                if (data.key === "http://tizen.org/appcontrol/data/selected")
                {
                    picLink = data.value[0];
                    console.log("selected image := "+picLink);
                }
            },
            onfailure: function()
            {
                //console.log('The launch application control failed');
            }
        };
 
        function onSuccess()
        {
            //console.log("launch application control succeed");
        }
 
        function onError(err)
        {
            alert(err.message);
        }
 
        tizen.application.launchAppControl(appControl, appId, onSuccess, onError, appControlReplyCallback);
    }

Usage

var button = document.querySelector('#camera');

button.onclick = takeAPicture;

 

Seoghyun Kang

Hello,

 

If you want to use the camera module directly, you need to use the getUserMedia API.

http://dev.w3.org/2011/webrtc/editor/getusermedia-20111130.html

 

But it does not support the rear-camera now. It only supports the front-camera :(

Please refer it.

Seoghyun Kang

There is a good news. You can use the rear-camera from Tizen 2.4 beta SDK.

Following is the contents in the release note of the Tizen 2.4 beta SDK. (https://developer.tizen.org/development/preview)

 

GetUserMedia - Facing Mode support
User can select front or rear camera using javaScript
W3C specification: http://www.w3.org/TR/mediacapture-streams/#constraints

 

I attached the sample code. Please refer it.

//Initialize function
var init = function () {
    navigator.getUserMedia(
			{
				audio: false, 
				video: true
			} 
			, null, null);
};

// window.onload can work without <body onload="">
window.onload = init;

 

Seoghyun Kang

I'm sorry. I missed some codes. 

 

If you want to use the rear camera, please use the following source.

The facingMode is the key point.

 

// Rear Camera
var rearCamera = function () {
    navigator.getUserMedia(
    	{
			audio: false, 
			video: true,
			facingMode: "environment"
		} 
		, null, null);
};

 

Vikram

facingMode: "environment" means source is facing away from the user (viewing the environment)

facingMode: "user" means the source is facing toward the user (a self-view camera)

GetUserMedia is new function in Tizen 2.4 and please create new project in 2.4 rather than Tizen 2.3.

Palitsyna

Hello,

here you can find an examole of usage of Camera Application Control and a kind of documentation for create_content AppControl:

https://developer.tizen.org/community/tip-tech/platform-application-controls-usage-web-app-part-3#_Camera_Application_Control

Hope this will help you.