CSFML

- Main Page
- Data Structures
- Files

- File List
- Globals

Functions
Image.h File Reference
`#include <SFML/Graphics/Export.h>`
`#include <SFML/Graphics/Color.h>`
`#include <SFML/Graphics/Rect.h>`
`#include <SFML/Graphics/Types.h>`
`#include <SFML/System/InputStream.h>`
`#include <SFML/System/Vector2.h>`
`#include <stddef.h>`

Go to the source code of this file.

## Functions

CSFML_GRAPHICS_API sfImage * | sfImage_create (unsigned int width, unsigned int height)
| Create an image. More...
CSFML_GRAPHICS_API sfImage * | sfImage_createFromColor (unsigned int width, unsigned int height, sfColor color)
| Create an image and fill it with a unique color. More...
CSFML_GRAPHICS_API sfImage * | sfImage_createFromPixels (unsigned int width, unsigned int height, const sfUint8 *pixels)
| Create an image from an array of pixels. More...
CSFML_GRAPHICS_API sfImage * | sfImage_createFromFile (const char *filename)
| Create an image from a file on disk. More...
CSFML_GRAPHICS_API sfImage * | sfImage_createFromMemory (const void *data, size_t size)
| Create an image from a file in memory. More...
CSFML_GRAPHICS_API sfImage * | sfImage_createFromStream (sfInputStream *stream)
| Create an image from a custom stream. More...
CSFML_GRAPHICS_API sfImage * | sfImage_copy (const sfImage *image)
| Copy an existing image. More...
CSFML_GRAPHICS_API void | sfImage_destroy (sfImage *image)
| Destroy an existing image. More...
CSFML_GRAPHICS_API sfBool | sfImage_saveToFile (const sfImage *image, const char *filename)
| Save an image to a file on disk. More...
CSFML_GRAPHICS_API sfVector2u | sfImage_getSize (const sfImage *image)
| Return the size of an image. More...
CSFML_GRAPHICS_API void | sfImage_createMaskFromColor (sfImage *image, sfColor color, sfUint8 alpha)
| Create a transparency mask from a specified color-key. More...
CSFML_GRAPHICS_API void | sfImage_copyImage (sfImage *image, const sfImage *source, unsigned int destX, unsigned int destY, sfIntRect sourceRect, sfBool applyAlpha)
| Copy pixels from an image onto another. More...
CSFML_GRAPHICS_API void | sfImage_setPixel (sfImage *image, unsigned int x, unsigned int y, sfColor color)
| Change the color of a pixel in an image. More...
CSFML_GRAPHICS_API sfColor | sfImage_getPixel (const sfImage *image, unsigned int x, unsigned int y)
| Get the color of a pixel in an image. More...
CSFML_GRAPHICS_API const sfUint8 * | sfImage_getPixelsPtr (const sfImage *image)
| Get a read-only pointer to the array of pixels of an image. More...
CSFML_GRAPHICS_API void | sfImage_flipHorizontally (sfImage *image)
| Flip an image horizontally (left <-> right) More...
CSFML_GRAPHICS_API void | sfImage_flipVertically (sfImage *image)
| Flip an image vertically (top <-> bottom) More...

## Function Documentation

CSFML_GRAPHICS_API sfImage* sfImage_copy | ( | const sfImage * | image | ) |

Copy an existing image.

Parameters

  image | Image to copy

Returns
  Copied object

CSFML_GRAPHICS_API void sfImage_copyImage | ( | sfImage * | image,
|  | const sfImage * | source,
|  | unsigned int | destX,
|  | unsigned int | destY,
|  | sfIntRect | sourceRect,
|  | sfBool | applyAlpha
| ) |  |

Copy pixels from an image onto another.

This function does a slow pixel copy and should not be used intensively. It can be used to prepare a complex static image from several others, but if you need this kind of feature in real-time you'd better use sfRenderTexture.

If sourceRect is empty, the whole image is copied. If applyAlpha is set to true, the transparency of source pixels is applied. If it is false, the pixels are copied unchanged with their alpha value.

Parameters

  image | Image object
  source | Source image to copy
  destX | X coordinate of the destination position
  destY | Y coordinate of the destination position
  sourceRect | Sub-rectangle of the source image to copy
  applyAlpha | Should the copy take in account the source transparency?

CSFML_GRAPHICS_API sfImage* sfImage_create | ( | unsigned int | width,
|  | unsigned int | height
| ) |  |

Create an image.

This image is filled with black pixels.

Parameters

  width | Width of the image
  height | Height of the image

Returns
  A new sfImage object

CSFML_GRAPHICS_API sfImage* sfImage_createFromColor | ( | unsigned int | width,
|  | unsigned int | height,
|  | sfColor | color
| ) |  |

Create an image and fill it with a unique color.

Parameters

  width | Width of the image
  height | Height of the image
  color | Fill color

Returns
  A new sfImage object

CSFML_GRAPHICS_API sfImage* sfImage_createFromFile | ( | const char * | filename | ) |

Create an image from a file on disk.

The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg. If this function fails, the image is left unchanged.

Parameters

  filename | Path of the image file to load

Returns
  A new sfImage object, or NULL if it failed

CSFML_GRAPHICS_API sfImage* sfImage_createFromMemory | ( | const void * | data,
|  | size_t | size
| ) |  |

Create an image from a file in memory.

The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg. If this function fails, the image is left unchanged.

Parameters

  data | Pointer to the file data in memory
  size | Size of the data to load, in bytes

Returns
  A new sfImage object, or NULL if it failed

CSFML_GRAPHICS_API sfImage* sfImage_createFromPixels | ( | unsigned int | width,
|  | unsigned int | height,
|  | const sfUint8 * | pixels
| ) |  |

Create an image from an array of pixels.

The pixel array is assumed to contain 32-bits RGBA pixels, and have the given width and height. If not, this is an undefined behaviour. If pixels is null, an empty image is created.

Parameters

  width | Width of the image
  height | Height of the image
  pixels | Array of pixels to copy to the image

Returns
  A new sfImage object

CSFML_GRAPHICS_API sfImage* sfImage_createFromStream | ( | sfInputStream * | stream | ) |

Create an image from a custom stream.

The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg. If this function fails, the image is left unchanged.

Parameters

  stream | Source stream to read from

Returns
  A new sfImage object, or NULL if it failed

CSFML_GRAPHICS_API void sfImage_createMaskFromColor | ( | sfImage * | image,
|  | sfColor | color,
|  | sfUint8 | alpha
| ) |  |

Create a transparency mask from a specified color-key.

This function sets the alpha value of every pixel matching the given color to alpha (0 by default), so that they become transparent.

Parameters

  image | Image object
  color | Color to make transparent
  alpha | Alpha value to assign to transparent pixels

CSFML_GRAPHICS_API void sfImage_destroy | ( | sfImage * | image | ) |

Destroy an existing image.

Parameters

  image | Image to delete

CSFML_GRAPHICS_API void sfImage_flipHorizontally | ( | sfImage * | image | ) |

Flip an image horizontally (left <-> right)

Parameters

  image | Image object

CSFML_GRAPHICS_API void sfImage_flipVertically | ( | sfImage * | image | ) |

Flip an image vertically (top <-> bottom)

Parameters

  image | Image object

CSFML_GRAPHICS_API sfColor sfImage_getPixel | ( | const sfImage * | image,
|  | unsigned int | x,
|  | unsigned int | y
| ) |  |

Get the color of a pixel in an image.

This function doesn't check the validity of the pixel coordinates, using out-of-range values will result in an undefined behaviour.

Parameters

  image | Image object
  x | X coordinate of pixel to get
  y | Y coordinate of pixel to get

Returns
  Color of the pixel at coordinates (x, y)

CSFML_GRAPHICS_API const sfUint8* sfImage_getPixelsPtr | ( | const sfImage * | image | ) |

Get a read-only pointer to the array of pixels of an image.

The returned value points to an array of RGBA pixels made of 8 bits integers components. The size of the array is getWidth() * getHeight() * 4. Warning: the returned pointer may become invalid if you modify the image, so you should never store it for too long. If the image is empty, a null pointer is returned.

Parameters

  image | Image object

Returns
  Read-only pointer to the array of pixels

CSFML_GRAPHICS_API sfVector2u sfImage_getSize | ( | const sfImage * | image | ) |

Return the size of an image.

Parameters

  image | Image object

Returns
  Size in pixels

CSFML_GRAPHICS_API sfBool sfImage_saveToFile | ( | const sfImage * | image,
|  | const char * | filename
| ) |  |

Save an image to a file on disk.

The format of the image is automatically deduced from the extension. The supported image formats are bmp, png, tga and jpg. The destination file is overwritten if it already exists. This function fails if the image is empty.

Parameters

  image | Image object
  filename | Path of the file to save

Returns
  sfTrue if saving was successful

CSFML_GRAPHICS_API void sfImage_setPixel | ( | sfImage * | image,
|  | unsigned int | x,
|  | unsigned int | y,
|  | sfColor | color
| ) |  |

Change the color of a pixel in an image.

This function doesn't check the validity of the pixel coordinates, using out-of-range values will result in an undefined behaviour.

Parameters

  image | Image object
  x | X coordinate of pixel to change
  y | Y coordinate of pixel to change
  color | New color of the pixel