语言

Menu
Sites
Language
Using Image widget

Hello,

I am trying to load image from application res directory eg. /res/images/logo.png. I've tried to do it in the way as in this tutorial: https://developer.tizen.org/documentation/articles/ui-sample-image-sample-overview BUT it doesn't work. Nothing happens, my code is exactly the same. What's more my Tizen IDE tells me that "app_get_resource" function is incorrect (implicit function declaration .... ). Can anyone help me?

响应

5 回复
Alex Ashirov

Hello,

app_get_resource() isn't system function. You need to add something like below in your source file:

static void
app_get_resource(const char *edj_file_in, char *edj_path_out, int edj_path_max)
{
    char *res_path = app_get_resource_path();
    if (res_path) {
        snprintf(edj_path_out, edj_path_max, "%s%s", res_path, edj_file_in);
        free(res_path);
    }
}

Mateusz Jarek

Thanks a lot Alex! Now it works. Anyway, what I am trying to do is to put an image and button into box container. Placing button is not a problem, but image - yes. I have tried one way:

char img_path[PATH_MAX] = { 0, };
app_get_resource("images/logo.png", img_path, PATH_MAX);

Evas_Object *image = elm_image_add(ad->hbox);
elm_image_file_set(ad->image, img_path, NULL);
evas_object_show(ad->image);
elm_box_pack_end(ad->hbox, ad->image);

and nothing happens, image is not displayed at all. Now I am a little confused. Is Image class (I mean this one: https://developer.tizen.org/documentation/mobile-native-app-programming/programming-guide/ui-creating-application-ui/widgets/image-widget) really a widget? If it's a widget why I cannot add it to box container? I think the problem is I am trying to draw an image on box container while it does not support any canvas operations. Any hints how to solve this problem?

 

colin Rao

try this two function evas_object_size_hint_weight_set(), evas_object_size_hint_align_set().

I use below code to show an image in box. 

    char filename[PATH_MAX];
    Evas_Object *ic = elm_icon_add(box1);
	evas_object_size_hint_align_set(ic, 0.2, 0.2);
    snprintf(filename, sizeof(filename), "%s%s", ICON_DIR, "head_man72.png");
    elm_image_file_set(ic, filename, NULL);
    evas_object_size_hint_min_set(ic, ad->screen_w*0.3, ad->screen_w*0.3);
    evas_object_show(ic);
    elm_box_pack_start(box1, ic);

 

Alex Ashirov

Hello,

It’s possible to add image widget to box container. You can take a look at sample:

\tizen-sdk\platforms\mobile-2.3\samples\native\core\Sample\Tizen Native\Native UI App\ApplicationStore\project\src\main.c

Mateusz Jarek

Thank you Colin, finally it worked :)