since: 3.10

Declaration [src]

gdk_window_create_similar_image_surface (
  GdkWindow* window,
  cairo_format_t format,
  int width,
  int height,
  int scale

Description [src]

Create a new image surface that is efficient to draw on the given window.

Initially the surface contents are all 0 (transparent if contents have transparency, black otherwise.)

The width and height of the new surface are not affected by the scaling factor of the window, or by the scale argument; they are the size of the surface in device pixels. If you wish to create an image surface capable of holding the contents of window you can use:

  int scale = gdk_window_get_scale_factor (window);
  int width = gdk_window_get_width (window) * scale;
  int height = gdk_window_get_height (window) * scale;

  // format is set elsewhere
  cairo_surface_t *surface =
    gdk_window_create_similar_image_surface (window,
                                             width, height,

Note that unlike cairo_surface_create_similar_image(), the new surface’s device scale is set to scale, or to the scale factor of window if scale is 0.

Available since: 3.10



Type: cairo_format_t

The format for the new surface.


Type: int

Width of the new surface.


Type: int

Height of the new surface.


Type: int

The scale of the new surface, or 0 to use same as window.

Return value

Type: cairo_surface_t

A pointer to the newly allocated surface. The caller owns the surface and should call cairo_surface_destroy() when done with it.

This function always returns a valid pointer, but it will return a pointer to a “nil” surface if other is already in an error state or any other error occurs.

The caller of the method takes ownership of the data, and is responsible for freeing it.