【问题标题】:changing codes implemeted with cairo_t to Cairo::RefPtr<Cairo::Context>将使用 cairo 实现的代码更改为 Cairo::RefPtr<Cairo::Context>
【发布时间】:2021-04-12 15:10:16
【问题描述】:

我有一些代码需要用 Cairo::RefPtrCairo::Context 重新实现......这有点令人困惑,因为我找不到使用模式的好例子,而我们有 Cairo::RefPtrCairo::Context 而不是cairo_t..

Cairo::RefPtr<Cairo::Surface> surface =
    Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, width, height);

Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);


cairo_pattern_t *cp = cairo_pattern_create_radial(x_off, y_off, 0, x_off, y_off, cent_point_radius);
cairo_pattern_add_color_stop_rgba(cp, 0.0, 0.7, 0.7, 0.7, 0.8);
cairo_pattern_add_color_stop_rgba(cp, 1.0, 0.1, 0.1, 0.1, 0.8);
cairo_set_source(cr, cp);

如何将“cp”更改为 cr->set_resource() .....cr 曾经是 cairo_t 可识别的内容,但后来我不得不将其更改为 Cairo::RefPtrCairo::Context

最好的问候

【问题讨论】:

    标签: gtk cairo gtkmm


    【解决方案1】:

    既然你已经决定用 C++ 的方式来做,为什么不直接用呢?

        // Create image surface.
        Cairo::RefPtr <Cairo::Surface> refSurface =
          Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
                                      nWidth,
                                      nHeight);
    
        // Create Cairo context for the image surface.
        Cairo::RefPtr <Cairo::Context> refContext =
          Cairo::Context::create(refSurface);
    
        // Create a radial gradient (pattern)
        Cairo::RefPtr <Cairo::RadialGradient> refPattern =
          Cairo::RadialGradient::create(x_off,
                                        y_off,
                                        0,
                                        x_off,
                                        y_off,
                                        cent_point_radius);
    
        // Add color stops to the pattern
        refPattern->add_color_stop_rgba(0.0,
                                        0.7,
                                        0.7,
                                        0.7,
                                        0.8);
        refPattern->add_color_stop_rgba(1.0,
                                        0.1,
                                        0.1,
                                        0.1,
                                        0.8);
    
        // Set the pattern as the source for the context.
        refContext->set_source(refPattern);
    
        // Add a closed path and fill...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-12
      • 1970-01-01
      • 2022-11-20
      • 1970-01-01
      • 2016-07-27
      • 2012-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多