Difference color when drawing image in Cairo

  c++, cairo, linux

i have an issue when using Cairo to draw image in linux system. the output image color not similar to original image if using cairo_image_surface_create method. like code below:

int width, height, channels;
unsigned char* data = stbi_load(imagePath.c_str(), &width, &height, &channels, STBI_rgb_alpha);
this->imageSource = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
unsigned char * surface_data = cairo_image_surface_get_data(this->imageSource);
memcpy(surface_data, data, width * height * 4 * sizeof(unsigned char));

But the color will the same when using cairo_image_surface_create_from_png (this api only support png format). see my code as below:

this->imageSource = cairo_image_surface_create_from_png(imagePath.c_str());

Also have a look on attach image to for clearly.

enter image description here

Source: Windows Questions C++