tizen - 如何在 tizen 原生小部件上设置和显示图像?
问题描述
我试图在 tizen 本机小部件上设置图像,但我不知道如何检索路径并应用它。下面是我的尝试:
//image
char full_path[PATH_MAX] = { 0, };
data_get_resource_path("images/testimg.png", full_path, (int) PATH_MAX); //getting error here.
Evas_Object *image;
image = elm_image_add(wid->conform);
elm_object_item_data_set(image, full_path); //how to set path?
elm_image_no_scale_set(image, EINA_TRUE);
elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE);
/* Tell the image to keep original aspect ratio */
elm_image_aspect_fixed_set(image, EINA_TRUE);
/* Then let the image fill the entire object */
elm_image_fill_outside_set(image, EINA_TRUE);
evas_object_show(image);
从 tizen 开发网站的图像文档中尝试过,没有专门用于路径设置的信息。
如何添加简单的图像并显示它?
解决方案
您可以使用相对文件路径并将图像文件设置为 efl 对象。
有许多示例应用程序。例如,BuddyUI Sample Application
展示如何获取图像文件路径
图像文件位于res/images/wc_contact_bg.png
.
#define IMAGE_CONTACT_BG "images/wc_contact_bg.png"
static bool app_create(void *user_data)
{
Evas_Object *win = NULL;
Eina_List *item_list = NULL;
Evas_Object *main_view_layout = NULL;
Evas_Object *naviframe = NULL;
int item_count = 0;
int i = 0;
char default_img_path[PATH_MAX] = { 0, };
char edj_path[PATH_MAX] = { 0, };
data_get_resource_path(EDJ_FILE, edj_path, sizeof(edj_path));
data_get_resource_path(IMAGE_CONTACT_BG, default_img_path, sizeof(default_img_path));
您可以通过 获取应用程序资源目录的绝对路径app_get_resource_path
。
void data_get_resource_path(const char *file_in, char *file_path_out, int file_path_max)
{
char *res_path = app_get_resource_path();
if (res_path) {
snprintf(file_path_out, file_path_max, "%s%s", res_path, file_in);
free(res_path);
}
}
您可以在下面的链接中找到很多信息。
文件系统目录层次结构
推荐阅读
- json - 如何将分组依据(值)转换为 json - django
- android - 安卓评论管理器
- terraform - Terraform vSphere 提供程序:添加 SR-IOV 网络适配器并通过 cloud-init 将其 MAC 地址传递给 VM
- python - 生产中的烧瓶 Web 应用程序中缺少 CSS
- excel - 如何处理 Vba 运行时错误“1004”:应用程序定义或对象定义错误
- java - Hadoop:有 1 个数据节点正在运行,并且在此操作中排除了 1 个节点
- flutter - 我在市场 Flutter App 上使用 Razorpay 作为支付网关。如何接受客户的金额 X 并将金额 X+Y 发送给卖家?
- java - 如何在方面关联中获取切入点上下文?
- gradle - 在构建损坏的情况下,下游开发人员的自定义 gradle 错误
- flutter - 断言失败:第 378 行 pos 10:“数据!= null”:必须向文本小部件提供非空字符串