语言

Menu
Sites
Language
How to capture a photo.

In Tizen native app i want to capture the photo . Can i do that using app control functionality.If yes how can i do that.

响应

15 回复
daniel kim

Hi,

Wish below code snippet can help you. this code can launch a camera and caputre an image.

   https://developer.tizen.org/community/code-snippet/web-code-snippet/camera-application-control

Regards

Palitsyna

Hello,

You can do it using http://tizen.org/appcontrol/operation/create_content operation. 

Here you can read more about Application Control: https://developer.tizen.org/dev-guide/web/2.3.0/org.tizen.mobile.web.appprogramming/html/guide/app_guide/launching_appcontrol.htm

 

rohit sijwali

I am able to capture the image. But can not get the image data

But what is the key to get the image data

app_control_get_extra_data

 

function

i m using 

http://tizen.org/appcontrol/data/selected

 

But getting error -126 which means

APP_CONTROL_ERROR_KEY_NOT_FOUND

 

Here is my code

 

 

#define CAMERA_APP_ID "tizen.camera"

#define CAMERA_OPERATION_ID "http://tizen.org/appcontrol/operation/create_content"

#define CAMERA_MIME_TYPE "image/jpeg"

 

 

 

#define CAMERA_ERROR -1

#define CAMERA_SUCCESS    0

 

static bool

foreach_extra_data_cb(app_control_h app_control, const char *key, void *user_data)

{

    char *value;

    int ret;

 

    ret = app_control_get_extra_data(app_control, key, &value);

    if ( ret == APP_CONTROL_ERROR_NONE)

    {

        dlog_print(DLOG_INFO, LOG_TAG, "[app_control_extra_data_cb] Succeeded: key(%s), value(%s)", key, value);

    }

    else

    {

        dlog_print(DLOG_ERROR, LOG_TAG, "[app_control_extra_data_cb] Failed: key(%s), Error code: %d", key, ret);

        return FALSE;

    }

    return TRUE;

}

 

static void _get_camera_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)

{

dlog_print(DLOG_ERROR, LOG_TAG, "Select Callback Called");

    char *data = NULL;

    int ret;

if (result == APP_CONTROL_RESULT_SUCCEEDED)

    app_control_foreach_extra_data(reply,foreach_extra_data_cb,NULL);

if (result == APP_CONTROL_RESULT_SUCCEEDED)

    {

        ret = app_control_get_extra_data(reply, APP_CONTROL_DATA_SELECTED, &data);

        if (ret == APP_CONTROL_ERROR_NONE){

            dlog_print(DLOG_ERROR, LOG_TAG, "Image Path %s",data);

        }

        else

        {

            dlog_print(DLOG_ERROR, LOG_TAG, "Error in path");

        }

    }

else

    {

        dlog_print(DLOG_ERROR, LOG_TAG, "Error in path");

    }

    if (data != NULL)

    {

        free(data);

    }

}

 

int openCamera()

{

    app_control_h app_control;

    int ret = app_control_create(&app_control);

    int retStatus=CAMERA_ERROR;

if (ret == APP_CONTROL_ERROR_NONE)

    {

            app_control_set_app_id(app_control, CAMERA_APP_ID);

            app_control_set_operation(app_control, CAMERA_OPERATION_ID);

            app_control_set_mime(app_control,CAMERA_MIME_TYPE);

 

 

 

            ret = app_control_send_launch_request(app_control, _get_camera_cb, NULL);

 

            if (ret == APP_CONTROL_ERROR_NONE )

            {

                dlog_print(DLOG_ERROR, LOG_TAG, "Open Camera Sucessfull!");

                retStatus=CAMERA_SUCCESS;

 

 

            }

            else

            {

                switch(ret)

                {

                case APP_CONTROL_ERROR_INVALID_PARAMETER:

                    dlog_print(DLOG_ERROR, LOG_TAG, "APP_CONTROL_ERROR_INVALID_PARAMETER");

                    break;

                case APP_CONTROL_ERROR_OUT_OF_MEMORY:

                    dlog_print(DLOG_ERROR, LOG_TAG, "APP_CONTROL_ERROR_OUT_OF_MEMORY");

                    break;

                case APP_CONTROL_ERROR_APP_NOT_FOUND:

                    dlog_print(DLOG_ERROR, LOG_TAG, "APP_CONTROL_ERROR_APP_NOT_FOUND");

                    break;

                case APP_CONTROL_ERROR_KEY_NOT_FOUND:

                    dlog_print(DLOG_ERROR, LOG_TAG, "APP_CONTROL_ERROR_KEY_NOT_FOUND");

                    break;

                case APP_CONTROL_ERROR_KEY_REJECTED:

                    dlog_print(DLOG_ERROR, LOG_TAG, "APP_CONTROL_ERROR_KEY_REJECTED");

                    break;

                case APP_CONTROL_ERROR_INVALID_DATA_TYPE:

                    dlog_print(DLOG_ERROR, LOG_TAG, "APP_CONTROL_ERROR_INVALID_DATA_TYPE");

                    break;

                case APP_CONTROL_ERROR_LAUNCH_REJECTED:

                    dlog_print(DLOG_ERROR, LOG_TAG, "APP_CONTROL_ERROR_LAUNCH_REJECTED");

                    break;

                case APP_CONTROL_ERROR_PERMISSION_DENIED:

                    dlog_print(DLOG_ERROR, LOG_TAG, "APP_CONTROL_ERROR_PERMISSION_DENIED");

                    break;

                case APP_CONTROL_ERROR_LAUNCH_FAILED:

                    dlog_print(DLOG_ERROR, LOG_TAG, "APP_CONTROL_ERROR_LAUNCH_FAILED");

                    break;

                case APP_CONTROL_ERROR_TIMED_OUT:

                    dlog_print(DLOG_ERROR, LOG_TAG, "APP_CONTROL_ERROR_TIMED_OUT");

                    break;

                }

            }

 

        }

      else

      {

          retStatus=CAMERA_ERROR;

        }

 

    if (app_control != NULL){

        app_control_destroy(app_control);

    }

    return retStatus;

}

 

 

 

rohit sijwali

Is i have to request the data explicitly?If yes how

Alex Dem

Hi
Looks like you are not the first who have faced with this problem:
https://developer.tizen.org/forums/native-application-development/getting-result-filemanager
https://developer.tizen.org/forums/native-application-development/getting-result-app_control_operation_create_content
It works for pick operation (if you use 'path' key instead of) but looks it does not work for create_content operation.
Alexey.

BeomChan Park

 see.

https://developer.tizen.org/sites/default/files/documentation/guide_to_developing_tizen_native_application_en_1.pdf

 page 830 

I hope It's what you want.

Palitsyna

Hello,

just FYI, app_control_send_launch_request() method requires the following privilege.

<privilege>http://tizen.org/privilege/appmanager.launch</privilege>

And probably you should add these privileges too:

<privilege>http://tizen.org/privilege/mediastorage</privilege>
<privilege>http://tizen.org/privilege/externalstorage</privilege>

Do not forget to add them into you tizen-manifest.xml file.

rohit sijwali

I added the privilege launch,mediastorage, external storage but can not get the image data.

BeomChan Park

try with this snippet

 

https://developer.tizen.org/ko/community/code-snippet/native-code-snippet/capture-image-or-movie-default-camera-application?tab=all

BeomChan Park

if you set app control operation as  APP_CONTROL_OPERATION_CREATE_CONTENT (=="http://tizen.org/appcontrol/operation/create_content") , mime type as "image/*" && "video/*" , you don't have to set app id explicitly. 

and if you add extra_data <"http://tizen.org/appcontrol/data/camera/allow_switch","true"> in app_control_h, you gonna able to switch video and image at default camera app.

main point of app_control's replying callback function is to get data using  function: app_control_get_extra_data_array. this is expained in linked snippet above.

 

I Hope you to get problem solved.

rohit sijwali

Thanks , its working .

rohit sijwali

Now i want to capture image of a certain resolution say 96 x 96 how can i do that.

Alex Dem

Hi,
I think you should use your camera application and set capture resolution with camera_set_capture_resolution api.
But you can't set any resolution , you should check possible capture resolutions with

int camera_foreach_supported_capture_resolution(camera_h camera,
        camera_supported_capture_resolution_cb callback, void *user_data);

not sure that you able to capture 96x96 photo.
Alexey.

rohit sijwali

Do i need to supply extra data in  the function   app_control_add_extra_data 

if yes then what should be the value.