sf::Image Class Reference

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

#include <Image.hpp>

Inheritance diagram for sf::Image:
sf::Resource< Image >

List of all members.

Public Member Functions

 Image ()
 Default constructor.
 Image (const Image &copy)
 Copy constructor.
 ~Image ()
 Destructor.
bool LoadFromFile (const std::string &filename)
 Load the image from a file.
bool LoadFromMemory (const void *data, std::size_t sizeInBytes)
 Load the image from a file in memory.
bool LoadFromPixels (unsigned int width, unsigned int height, const Uint8 *pixels)
 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, const Color &color=Color(0, 0, 0))
 Create an empty image.
void CreateMaskFromColor (const Color &transparentColor, 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 &color)
 Change the color of a pixel.
const ColorGetPixel (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 UpdatePixels (const Uint8 *pixels)
 Update the whole image from an array of pixels.
void UpdatePixels (const Uint8 *pixels, const IntRect &rectangle)
 Update a sub-rectangle of the image from an array of pixels.
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 &rectangle) const
 Convert a subrect expressed in pixels, into float texture coordinates.
Imageoperator= (const Image &other)
 Assignment operator.

Static Public Member Functions

static unsigned int GetMaximumSize ()
 Get the maximum image size according to hardware support.
static unsigned int GetValidSize (unsigned int size)
 Get a valid image size according to hardware support.

Friends

class Renderer
class RenderImage

Detailed Description

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

Definition at line 48 of file Image.hpp.


Constructor & Destructor Documentation

sf::Image::Image (  ) 

Default constructor.

Definition at line 44 of file Image.cpp.

sf::Image::Image ( const Image copy  ) 

Copy constructor.

Parameters:
copy : instance to copy

Definition at line 62 of file Image.cpp.

sf::Image::~Image (  ) 

Destructor.

Definition at line 87 of file Image.cpp.


Member Function Documentation

void sf::Image::Bind (  )  const

Bind the image for rendering.

Definition at line 490 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
applyAlpha : Should the copy take in account the source transparency?

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

Definition at line 244 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.

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 333 of file Image.cpp.

bool sf::Image::Create ( unsigned int  width,
unsigned int  height,
const Color color = Color(0, 0, 0) 
)

Create an empty image.

Parameters:
width : Image width
height : Image height
color : Image color
Returns:
True if creation was successful

Definition at line 196 of file Image.cpp.

void sf::Image::CreateMaskFromColor ( const Color transparentColor,
Uint8  alpha = 0 
)

Create transparency mask from a specified colorkey.

Parameters:
transparentColor : Color to become transparent
alpha : Alpha value to assign to transparent pixels

Definition at line 223 of file Image.cpp.

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

Return the height of the image.

Returns:
Height in pixels

Definition at line 536 of file Image.cpp.

unsigned int sf::Image::GetMaximumSize (  )  [static]

Get the maximum image size according to hardware support.

Returns:
Maximum size allowed for images, in pixels

Definition at line 587 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 407 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.

Returns:
Const pointer to the array of pixels

Definition at line 429 of file Image.cpp.

FloatRect sf::Image::GetTexCoords ( const IntRect rectangle  )  const

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

Parameters:
rectangle : Sub-rectangle of image to convert
Returns:
Texture coordinates corresponding to the sub-rectangle

Definition at line 555 of file Image.cpp.

unsigned int sf::Image::GetValidSize ( unsigned int  size  )  [static]

Get a valid image size according to hardware support.

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

Definition at line 599 of file Image.cpp.

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

Return the width of the image.

Returns:
Width in pixels

Definition at line 527 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 545 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 97 of file Image.cpp.

bool sf::Image::LoadFromMemory ( const void *  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 119 of file Image.cpp.

bool sf::Image::LoadFromPixels ( unsigned int  width,
unsigned int  height,
const Uint8 *  pixels 
)

Load the image directly from an array of pixels.

Parameters:
width : Image width
height : Image height
pixels : Pointer to the pixels in memory (assumed format is RGBA)
Returns:
True if loading was successful

Definition at line 148 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 624 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 183 of file Image.cpp.

void sf::Image::SetPixel ( unsigned int  x,
unsigned int  y,
const Color color 
)

Change the color of a pixel.

Parameters:
x : X coordinate of pixel in the image
y : Y coordinate of pixel in the image
color : New color for pixel (x, y)

Definition at line 384 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 503 of file Image.cpp.

void sf::Image::UpdatePixels ( const Uint8 *  pixels,
const IntRect rectangle 
)

Update a sub-rectangle of the image from an array of pixels.

Warning: for performances reasons, this function doesn't perform any check; thus you're responsible of ensuring that rectangle does not exceed the image size, and that pixels contains enough elements.

Parameters:
rectangle : Sub-rectangle of the image to update
pixels : Array of pixels to write to the image

Definition at line 468 of file Image.cpp.

void sf::Image::UpdatePixels ( const Uint8 *  pixels  ) 

Update the whole image from an array of pixels.

Parameters:
pixels : Array of pixels to write to the image

Definition at line 449 of file Image.cpp.


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