Cairo draw PNG image?

Cairo draw PNG image?

BY 28 Nov 2015 Native Application Development

Hi.

I’m trying to draw an PNG image to tizen phone.

Object inside PNG image is displayed good but transparent background of PNG image displayed in black

My code like bellow. Did i wrong something?

static void
win_resize_cb(void *data, Evas *e , Evas_Object *obj , void *event_info)
{
    appdata_s *ad = data;

	char img_path[255] = {0};
	int img_w, img_h;
	snprintf(img_path, sizeof(img_path) , ASSET_PATH"/chrome.png");
	ad->surface = cairo_image_surface_create_from_png(img_path);
	ad->cairo = cairo_create(ad->surface);
	img_w = cairo_image_surface_get_width (ad->surface);
	img_h = cairo_image_surface_get_height(ad->surface);

	evas_object_image_size_set(ad->img, img_w, img_h);
	evas_object_resize(ad->img, img_w, img_h);
	evas_object_show(ad->img);

	//cairo_set_operator(ad->cairo, CAIRO_OPERATOR_CLEAR);
	cairo_set_source_surface(ad->cairo, ad->surface, 0, 0);
	cairo_paint(ad->cairo);
	cairo_surface_destroy (ad->surface);

	unsigned char * imageData = cairo_image_surface_get_data(cairo_get_target(ad->cairo));
	evas_object_image_data_set(ad->img, imageData);
	evas_object_image_data_update_add(ad->img, 0, 0, img_w, img_h);
}

static bool
app_create(void *data)
{
	appdata_s *ad = data;

	/* Window */
	ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
	elm_win_autodel_set(ad->win, EINA_TRUE);

	if (elm_win_wm_rotation_supported_get(ad->win)) {
		int rots[4] = { 0, 90, 180, 270 };
		elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
	}

	evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
	eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad);
	evas_object_event_callback_add(ad->win, EVAS_CALLBACK_RESIZE, win_resize_cb, ad);

	/* Show window after base gui is set up */
	evas_object_show(ad->win);

	ad->img = evas_object_image_filled_add(evas_object_evas_get(ad->win));
	evas_object_show(ad->img);

	return true;
}

 

Written by