# class Cairo::ImageSurface

image surface

### Public Class Methods

from_png(p1) click to toggle source

    static VALUE
    cr_image_surface_create_from_png_generic (VALUE klass, VALUE target)
    {
      VALUE rb_surface;
      cairo_surface_t *surface;

      if (rb_respond_to (target, rb_cairo__io_id_read))
        surface = cr_image_surface_create_from_png_stream (target);
      else
        surface = cr_image_surface_create_from_png (target);

      rb_cairo_surface_check_status (surface);
      rb_surface = cr_surface_allocate (klass);
      DATA_PTR (rb_surface) = surface;
      return rb_surface;
    }

new(*args) click to toggle source

    static VALUE
    cr_image_surface_initialize (int argc, VALUE *argv, VALUE self)
    {
      cairo_surface_t *surface;
      VALUE arg1, arg2, arg3, arg4, arg5;
      int n;

      n = rb_scan_args (argc, argv, "23", &arg1, &arg2, &arg3, &arg4, &arg5);

      if (n == 2)
        surface = cr_image_surface_create (self, Qnil, arg1, arg2);
      else if (n == 3)
        surface = cr_image_surface_create (self, arg1, arg2, arg3);
      else if (n == 5)
        surface =
          cr_image_surface_create_for_data (self, arg1, arg2, arg3, arg4, arg5);
      else
        rb_raise (rb_eArgError,
                  "invalid argument (expect "
                  "(width, height) or "
                  "(format, width, height) or "
                  "(data, format, width, height, stride)): %s",
                  rb_cairo__inspect (rb_ary_new3 (4, arg1, arg2, arg3, arg4)));

      rb_cairo_surface_check_status (surface);
      DATA_PTR (self) = surface;
      if (rb_block_given_p ())
        rb_cairo__surface_yield_and_finish (self);
      return Qnil;
    }

### Public Instance Methods

data() click to toggle source

    static VALUE
    cr_image_surface_get_data (VALUE self)
    {
      unsigned char *data;
      cairo_surface_t *surface;

      surface = _SELF;
      data = cairo_image_surface_get_data (surface);

      if (data)
        return rb_str_new ((const char *)data,
                           cairo_image_surface_get_stride (surface) *
                           cairo_image_surface_get_height (surface));
      else
        return Qnil;
    }

format() click to toggle source

    static VALUE
    cr_image_surface_get_format (VALUE self)
    {
      return INT2NUM (cairo_image_surface_get_format (_SELF));
    }

height() click to toggle source

    static VALUE
    cr_image_surface_get_height (VALUE self)
    {
      return INT2NUM (cairo_image_surface_get_height (_SELF));
    }

stride() click to toggle source

    static VALUE
    cr_image_surface_get_stride (VALUE self)
    {
      return INT2NUM (cairo_image_surface_get_stride (_SELF));
    }

width() click to toggle source

    static VALUE
    cr_image_surface_get_width (VALUE self)
    {
      return INT2NUM (cairo_image_surface_get_width (_SELF));
    }