CxImage cx;
cx.Load(image_path, CXIMAGE_FORMAT_JPG);
unsigned char* pImageBytes = (unsigned char*)cx.GetBits();
int width = cx.GetWidth();
int height = cx.GetHeight();
long size_origin = cx.GetSize();
long size_dest = size_origin + width*height;
long stride_origin = size_origin/height;
long stride_dest = size_dest/height;
int bpp_origin = stride_origin/ width;
int bpp_dest = 4;
unsigned char* pCairoBytes = (unsigned char*)malloc(size_dest);
const unsigned char alpha = 0xff;
int i, j;
long row_start_pos_origin, row_start_pos_dest;
for(i = 0; i < height; i++ )
{
row_start_pos_origin = (height - i - 1) * stride_origin;
row_start_pos_dest = i * stride_dest;
for(j = 0; j < width; j++)
{
memcpy( (pCairoBytes + row_start_pos_dest + j*bpp_dest),
(pImageBytes + row_start_pos_origin + j*bpp_origin), 3); // rgb
memcpy( (pCairoBytes + row_start_pos_dest + j*bpp_dest + 3), &alpha, 1); // alpha
}
}
cairo_surface_t*
image_surface = cairo_image_surface_create_for_data(pCairoBytes, CAIRO_FROMAT_ARGB32,
width, height, stride_dest);
cximage 를 이용해 그림 파일을 불러오고 cairo 로 그린다.

