【问题标题】:Cairo Library: produce a png file with white backgroundCairo Library:生成一个白色背景的 png 文件
【发布时间】:2018-01-18 14:40:00
【问题描述】:

我在 INTERNET 中搜索了与该主题相关的内容,但我发现只有想要保存背景透明的 png 文件的人。

我报告了我目前使用并生成背景透明的 png 的源代码:

cairo_surface_t *surface; // Declarations
cairo_t *cr;

// Creations of the surface
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,3508,2480);

// Contest
cr = cairo_create(surface);

// Moving the plot to center in the page
cairo_translate(cr, 200,200);

// Scaling the plot
cairo_scale(cr,1.8,1.8);

// Make all the necessary actions to produce the plot 
do_drawing(cr);

// write the plot on the file png
cairo_surface_write_to_png(surface, "image.png");

// End
cairo_surface_destroy(surface);
cairo_destroy(cr);

我也使用了表面 CAIRO_FORMAT_RGB24,但我得到了一个黑色矩形,如绘图。

你能帮帮我吗? 谢谢你

【问题讨论】:

    标签: c png cairo


    【解决方案1】:
    cairo_surface_t *surface; // Declarations
    cairo_t *cr;
    
    // Creations of the surface
    // XXX: Changed to format RGB24; if you don't need transparency, well.
    surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,3508,2480);
    
    // Contest
    cr = cairo_create(surface);
    
    // Draw background XXXXXXXXXXXXXXXXXX
    cairo_save(cr);
    cairo_set_source_rgb(cr, 1, 1, 1);
    cairo_paint(cr);
    cairo_restore(cr);
    
    // Moving the plot to center in the page
    cairo_translate(cr, 200,200);
    
    // Scaling the plot
    cairo_scale(cr,1.8,1.8);
    
    // Make all the necessary actions to produce the plot 
    do_drawing(cr);
    
    // write the plot on the file png
    cairo_surface_write_to_png(surface, "image.png");
    
    // End
    cairo_surface_destroy(surface);
    cairo_destroy(cr);
    

    【讨论】:

      【解决方案2】:

      你需要画一个不透明的背景,看看 cairo_set_source_rgb 函数。

      【讨论】:

        猜你喜欢
        • 2015-06-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-20
        • 2016-01-12
        • 2014-08-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多