clinuxgtkstm32cairo

Cairo STM32MP1 cairo_surface_write_to_png always returns CAIRO_STATUS_WRITE_ERROR


I am trying to write a PNG file. I am always getting a write error (CAIRO_STATUS_WRITE_ERROR).

    cairo_surface_t *image_surface = cairo_surface_create_similar_image(pBitmap -> mainSurface,
                     CAIRO_FORMAT_RGB24, pBitmap -> geom.width, pBitmap -> geom.height);
    cairo_t *cr = cairo_create(image_surface);
    cairo_set_source_surface(cr, pBitmap -> mainSurface, 0, 0);
    cairo_paint(cr);
    cairo_status_t cairo_errCode;

    if(pFile)
    {
        char template[] = "./fileXXXXXX.png";
        char *tempFileName = mkdtemp(template);
        if(tempFileName)
        {
            if((cairo_errCode = cairo_surface_write_to_png(image_surface, tempFileName)) == CAIRO_STATUS_SUCCESS)
            {

As far as I understand it clearly indicates a file error. I tried many locations to see if it was not a permissions problem.


Solution

  • mkdtemp returns a new temporary directory.

    You want mkstemp (a new temporary file).