# sf::Image Class Reference

Image is the low-level class for loading and manipulating images. More...

`#include <Image.hpp>`

Inheritance diagram for sf::Image:

List of all members.

## Public Member Functions

| Image ()
| Default constructor.
| Image (const Image &Copy)
| Copy constructor.
| Image (unsigned int Width, unsigned int Height, const Color &Col=Color(0, 0, 0, 255))
| Construct an empty image.
| Image (unsigned int Width, unsigned int Height, const Uint8 *Data)
| Construct the image from pixels in memory.
| ~Image ()
| Destructor.
bool | LoadFromFile (const std::string &Filename)
| Load the image from a file.
bool | LoadFromMemory (const char *Data, std::size_t SizeInBytes)
| Load the image from a file in memory.
bool | LoadFromPixels (unsigned int Width, unsigned int Height, const Uint8 *Data)
| Load the image directly from an array of pixels.
bool | SaveToFile (const std::string &Filename) const
| Save the content of the image to a file.
bool | Create (unsigned int Width, unsigned int Height, Color Col=Color(0, 0, 0, 255))
| Create an empty image.
void | CreateMaskFromColor (Color ColorKey, Uint8 Alpha=0)
| Create transparency mask from a specified colorkey.
void | Copy (const Image &Source, unsigned int DestX, unsigned int DestY, const IntRect &SourceRect=IntRect(0, 0, 0, 0), bool ApplyAlpha=false)
| Copy pixels from another image onto this one.
bool | CopyScreen (RenderWindow &Window, const IntRect &SourceRect=IntRect(0, 0, 0, 0))
| Create the image from the current contents of the given window.
void | SetPixel (unsigned int X, unsigned int Y, const Color &Col)
| Change the color of a pixel.
const Color & | GetPixel (unsigned int X, unsigned int Y) const
| Get a pixel from the image.
const Uint8 * | GetPixelsPtr () const
| Get a read-only pointer to the array of pixels (RGBA 8 bits integers components) Array size is GetWidth() x GetHeight() x 4 This pointer becomes invalid if you reload or resize the image.
void | Bind () const
| Bind the image for rendering.
void | SetSmooth (bool Smooth)
| Enable or disable image smooth filter.
unsigned int | GetWidth () const
| Return the width of the image.
unsigned int | GetHeight () const
| Return the height of the image.
bool | IsSmooth () const
| Tells whether the smooth filtering is enabled or not.
FloatRect | GetTexCoords (const IntRect &Rect) const
| Convert a subrect expressed in pixels, into float texture coordinates.
Image & | operator= (const Image &Other)
| Assignment operator.

## Static Public Member Functions

static unsigned int | GetValidTextureSize (unsigned int Size)
| Get a valid texture size according to hardware support.

## Detailed Description

Image is the low-level class for loading and manipulating images.

Definition at line 46 of file Image.hpp.

## Constructor & Destructor Documentation

sf::Image::Image | ( |  | ) |

Default constructor.

Definition at line 43 of file Image.cpp.

sf::Image::Image | ( | const Image & | Copy | ) |

Copy constructor.

Parameters:

  | Copy | : instance to copy

Definition at line 60 of file Image.cpp.

sf::Image::Image | ( | unsigned int | Width,
|  | unsigned int | Height,
|  | const Color & | Col = `Color(0, 0, 0, 255)` |
| ) |  |  |

Construct an empty image.

Parameters:

  | Width | : Image width
  | Height | : Image height
  | Col | : Image color (black by default)

Definition at line 79 of file Image.cpp.

sf::Image::Image | ( | unsigned int | Width,
|  | unsigned int | Height,
|  | const Uint8 * | Data |
| ) |  |  |

Construct the image from pixels in memory.

Parameters:

  | Width | : Image width
  | Height | : Image height
  | Data | : Pointer to the pixels in memory (assumed format is RGBA)

Definition at line 96 of file Image.cpp.

sf::Image::~Image | ( |  | ) |

Destructor.

Definition at line 113 of file Image.cpp.

## Member Function Documentation

void sf::Image::Bind | ( |  | ) | const

Bind the image for rendering.

Definition at line 473 of file Image.cpp.

void sf::Image::Copy | ( | const Image & | Source,
|  | unsigned int | DestX,
|  | unsigned int | DestY,
|  | const IntRect & | SourceRect = `IntRect(0, 0, 0, 0)`,
|  | bool | ApplyAlpha = `false` |
| ) |  |  |

Copy pixels from another image onto this one.

This function does a slow pixel copy and should only be used at initialization time

Parameters:

  | 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 (empty by default - entire image)
  | ApplyAlpha | : Should the copy take in account the source transparency? (false by default)

This function does a slow pixel copy and should only be used at initialization time

Definition at line 270 of file Image.cpp.

bool sf::Image::CopyScreen | ( | RenderWindow & | Window,
|  | const IntRect & | SourceRect = `IntRect(0, 0, 0, 0)` |
| ) |  |  |

Create the image from the current contents of the given window.

Create the image from the current contents of the given window.

Parameters:

  | Window | : Window to capture
  | SourceRect | : Sub-rectangle of the screen to copy (empty by default - entire image)

Returns:
  True if copy was successful

Definition at line 358 of file Image.cpp.

bool sf::Image::Create | ( | unsigned int | Width,
|  | unsigned int | Height,
|  | Color | Col = `Color(0, 0, 0, 255)` |
| ) |  |  |

Create an empty image.

Parameters:

  | Width | : Image width
  | Height | : Image height
  | Col | : Image color (black by default)

Returns:
  True if creation was successful

Definition at line 222 of file Image.cpp.

void sf::Image::CreateMaskFromColor | ( | Color | ColorKey,
|  | Uint8 | Alpha = `0` |
| ) |  |  |

Create transparency mask from a specified colorkey.

Parameters:

  | ColorKey | : Color to become transparent
  | Alpha | : Alpha value to use for transparent pixels (0 by default)

Definition at line 249 of file Image.cpp.

unsigned int sf::Image::GetHeight | ( |  | ) | const

Return the height of the image.

Returns:
  Height in pixels

Definition at line 526 of file Image.cpp.

const Color & sf::Image::GetPixel | ( | unsigned int | X,
|  | unsigned int | Y |
| ) |  |  | const

Get a pixel from the image.

Parameters:

  | X | : X coordinate of pixel in the image
  | Y | : Y coordinate of pixel in the image

Returns:
  Color of pixel (X, Y)

Definition at line 431 of file Image.cpp.

const Uint8 * sf::Image::GetPixelsPtr | ( |  | ) | const

Get a read-only pointer to the array of pixels (RGBA 8 bits integers components) Array size is GetWidth() x GetHeight() x 4 This pointer becomes invalid if you reload or resize the image.

Get a read-only pointer to the array of pixels (RGBA 8 bits integers components) Array size is GetWidth() x GetHeight() x 4 This pointer becomes invalid if you reload or resize the image.

Returns:
  Const pointer to the array of pixels

Definition at line 453 of file Image.cpp.

FloatRect sf::Image::GetTexCoords | ( | const IntRect & | Rect | ) | const

Convert a subrect expressed in pixels, into float texture coordinates.

Convert a subrect expressed in pixels, into float texture coordinates.

Parameters:

  | Rect | : Sub-rectangle of image to convert

Returns:
  Texture coordinates corresponding to the sub-rectangle

Definition at line 545 of file Image.cpp.

unsigned int sf::Image::GetValidTextureSize | ( | unsigned int | Size | ) | `[static]`

Get a valid texture size according to hardware support.

Parameters:

  | Size | : Size to convert

Returns:
  Valid nearest size (greater than or equal to specified size)

Definition at line 560 of file Image.cpp.

unsigned int sf::Image::GetWidth | ( |  | ) | const

Return the width of the image.

Returns:
  Width in pixels

Definition at line 517 of file Image.cpp.

bool sf::Image::IsSmooth | ( |  | ) | const

Tells whether the smooth filtering is enabled or not.

Returns:
  True if image smoothing is enabled

Definition at line 535 of file Image.cpp.

bool sf::Image::LoadFromFile | ( | const std::string & | Filename | ) |

Load the image from a file.

Parameters:

  | Filename | : Path of the image file to load

Returns:
  True if loading was successful

Definition at line 123 of file Image.cpp.

bool sf::Image::LoadFromMemory | ( | const char * | Data,
|  | std::size_t | SizeInBytes |
| ) |  |  |

Load the image from a file in memory.

Parameters:

  | Data | : Pointer to the file data in memory
  | SizeInBytes | : Size of the data to load, in bytes

Returns:
  True if loading was successful

Definition at line 145 of file Image.cpp.

bool sf::Image::LoadFromPixels | ( | unsigned int | Width,
|  | unsigned int | Height,
|  | const Uint8 * | Data |
| ) |  |  |

Load the image directly from an array of pixels.

Parameters:

  | Width | : Image width
  | Height | : Image height
  | Data | : Pointer to the pixels in memory (assumed format is RGBA)

Returns:
  True if loading was successful

Definition at line 174 of file Image.cpp.

Image & sf::Image::operator= | ( | const Image & | Other | ) |

Assignment operator.

Parameters:

  | Other | : instance to assign

Returns:
  Reference to the image

Definition at line 585 of file Image.cpp.

bool sf::Image::SaveToFile | ( | const std::string & | Filename | ) | const

Save the content of the image to a file.

Parameters:

  | Filename | : Path of the file to save (overwritten if already exist)

Returns:
  True if saving was successful

Definition at line 209 of file Image.cpp.

void sf::Image::SetPixel | ( | unsigned int | X,
|  | unsigned int | Y,
|  | const Color & | Col |
| ) |  |  |

Change the color of a pixel.

Parameters:

  | X | : X coordinate of pixel in the image
  | Y | : Y coordinate of pixel in the image
  | Col | : New color for pixel (X, Y)

Definition at line 408 of file Image.cpp.

void sf::Image::SetSmooth | ( | bool | Smooth | ) |

Enable or disable image smooth filter.

Enable or disable image smoothing filter.

This parameter is enabled by default

Parameters:

  | Smooth | : True to enable smoothing filter, false to disable it

Definition at line 490 of file Image.cpp.

The documentation for this class was generated from the following files:

- Image.hpp
- Image.cpp