我可以改变现有Evas_Object的图像文件吗?

问题描述 投票:0回答:1

我正在用Tizen Native使用EFL库开发一个手表脸。在用EFL库创建了许多对象后。

Evas_Object *view_create_parts(Evas_Object *parent, const char *image_path,
    int position_x, int position_y, int size_w, int size_h) {
    Evas_Object *parts = NULL;

    parts = elm_image_add(parent);

    elm_image_file_set(parts, image_path, NULL);

    evas_object_move(parts, position_x, position_y);
    evas_object_resize(parts, size_w, size_h);

    evas_object_show(parts);

    return parts;
}

我想在以后根据需要改变一些现有对象的图像。这可能吗?我知道我也可以将所有可能的变体作为单个对象加载,并相应地显示出对象。但我发现只改变现有对象的图像更简单,更优雅。另外,这可能也会使用更少的资源。

我试过这样做。

elm_image_file_set(<part_I_want_to_change_its_image>, "images/newimage.png", NULL));

但是这个对象并没有改变成正确的图像 而是消失了。有什么好办法吗?

tizen tizen-wearable-sdk tizen-native-app efl
1个回答
0
投票

是的,elm_image支持图像转换.但是普通的图像是包含在容器部件中的,或者作为布局的一个区域,但是在你的例子中,它似乎是一个孤立的和画布上的图像。

在这种情况下,如果图像文件被改变,旧的几何体是没有意义的,所以你需要设置一个新的几何体值,在调用elm_image_file_set后做以下操作。

evas_object_move(parts, position_x, position_y);
evas_object_resize(parts, size_w, size_h);

0
投票

为了让人能够跟上,我在其中一个包含的样本 "Chronograph Watch "上进行测试。在文件view.c中,有一个功能是 view_chronograph_create_parts(). 在这里,我所做的就是把代码从。

case PARTS_TYPE_HANDS_HOUR:
    s_info.hand_hour = part; // at this point, the image is already set
    break;

改为:

case PARTS_TYPE_HANDS_HOUR:
    s_info.hand_hour = part; // at this point, the image is already set

    elm_image_file_set(s_info.hand_hour, "images/chrono_hand_min.png", NULL);

    // I tried these two lines as well, but no change
    evas_object_move(s_info.hand_hour, 166, 0);
    evas_object_resize(s_info.hand_hour, 28, 360);

    break;

我的想法是在最初设置好时针后改变时针的图像,看它是不是 elm_image_file_set() 是成功地改变了图像。但我得到的是时针根本看不到。


0
投票

我终于发现自己做错了什么。我不知道图像路径要如何形成。非工作方法。

elm_image_file_set(s_info.hand_hour, "images/new_image.png", NULL);

工作方法:

char image_path[PATH_MAX] = { 0, };
data_get_resource_path("images/new_image.png", image_path, sizeof(image_path));
elm_image_file_set(s_info.hand_hour, image_path, NULL);
© www.soinside.com 2019 - 2024. All rights reserved.