raylib-cpp
C++ object-oriented wrapper library for raylib.
Public Member Functions | Static Public Member Functions | List of all members
raylib::Image Class Reference

Image type, bpp always RGBA (32bit) More...

Public Member Functions

 Image (const ::Font &font, const std::string &text, float fontSize, float spacing, ::Color tint={255, 255, 255, 255})
 
 Image (const ::Image &image)
 
 Image (const ::Texture2D &texture)
 
 Image (const std::string &fileName)
 
 Image (const std::string &fileName, int *frames)
 
 Image (const std::string &fileName, int width, int height, int format, int headerSize)
 
 Image (const std::string &fileType, const unsigned char *fileData, int dataSize)
 
 Image (int width, int height, ::Color color={255, 255, 255, 255})
 
Image & AlphaCrop (float threshold)
 Crop image depending on alpha value.
 
Image & AlphaMask (const ::Image &alphaMask)
 Apply alpha mask to image.
 
Image & AlphaPremultiply ()
 Premultiply alpha channel.
 
Image & ClearBackground (::Color color={0, 0, 0, 255})
 Clear image background with given color.
 
Image & ColorBrightness (int brightness)
 Modify image color: brightness. More...
 
Image & ColorContrast (float contrast)
 Modify image color: contrast. More...
 
Image & ColorGrayscale ()
 Modify image color: grayscale.
 
Image & ColorInvert ()
 Modify image color: invert.
 
Image & ColorReplace (::Color color, ::Color replace)
 Modify image color: replace color.
 
Image & ColorTint (::Color color={255, 255, 255, 255})
 Modify image color: tint.
 
inline ::Image Copy ()
 Create an image duplicate (useful for transformations)
 
Image & Crop (::Rectangle crop)
 Crop an image to area defined by a rectangle.
 
Image & Crop (::Vector2 size)
 Crop an image to a new given width and height based on a vector.
 
Image & Crop (int offsetX, int offsetY, int newWidth, int newHeight)
 Crop an image to area defined by a rectangle.
 
Image & Dither (int rBpp, int gBpp, int bBpp, int aBpp)
 Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
 
Image & Draw (const ::Image &src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint={255, 255, 255, 255})
 
Image & DrawCircle (::Vector2 center, int radius, ::Color color={255, 255, 255, 255})
 
Image & DrawCircle (int centerX, int centerY, int radius, ::Color color={255, 255, 255, 255})
 
Image & DrawLine (::Vector2 start, ::Vector2 end, ::Color color={255, 255, 255, 255})
 
Image & DrawLine (int startPosX, int startPosY, int endPosX, int endPosY, ::Color color={255, 255, 255, 255})
 
Image & DrawPixel (::Vector2 position, ::Color color={255, 255, 255, 255})
 
Image & DrawPixel (int posX, int posY, ::Color color={255, 255, 255, 255})
 Draw pixel within an image.
 
Image & DrawRectangle (::Rectangle rec, ::Color color={255, 255, 255, 255})
 
Image & DrawRectangle (int posX, int posY, int width, int height, ::Color color={255, 255, 255, 255})
 
Image & DrawRectangle (Vector2 position, Vector2 size, ::Color color={255, 255, 255, 255})
 
Image & DrawRectangleLines (::Rectangle rec, int thick=1, ::Color color={255, 255, 255, 255})
 
Image & DrawText (const ::Font &font, const std::string &text, ::Vector2 position, float fontSize, float spacing, ::Color tint={255, 255, 255, 255})
 
Image & DrawText (const std::string &text, ::Vector2 position, int fontSize, ::Color color={255, 255, 255, 255})
 
Image & DrawText (const std::string &text, int x, int y, int fontSize, ::Color color={255, 255, 255, 255})
 
bool Export (const std::string &fileName)
 Export image data to file, returns true on success.
 
bool ExportAsCode (const std::string &fileName)
 Export image as code file defining an array of bytes, returns true on success.
 
Image & FlipHorizontal ()
 Flip image horizontally.
 
Image & FlipVertical ()
 Flip image vertically.
 
Image & Format (int newFormat)
 Convert image data to desired format.
 
inline ::Image FromImage (::Rectangle rec)
 Create an image from another image piece.
 
Rectangle GetAlphaBorder (float threshold) const
 Get image alpha border rectangle. More...
 
void * GetData () const
 Retrieves the data value for the object. More...
 
int GetFormat () const
 Retrieves the format value for the object. More...
 
int GetHeight () const
 Retrieves the height value for the object. More...
 
int GetMipmaps () const
 Retrieves the mipmaps value for the object. More...
 
int GetPixelDataSize ()
 Returns the pixel data size of the image. More...
 
inline ::Vector2 GetSize ()
 Retrieve the width and height of the image.
 
int GetWidth () const
 Retrieves the width value for the object. More...
 
void Load (const std::string &fileName)
 Load image from file into CPU memory (RAM)
 
void LoadAnim (const std::string &fileName, int *frames)
 Load image sequence from file (frames appended to image.data).
 
inline ::Color * LoadColors ()
 Load color data from image as a Color array (RGBA - 32bit)
 
void LoadFromMemory (const std::string &fileType, const unsigned char *fileData, int dataSize)
 Load image from memory buffer, fileType refers to extension: i.e. More...
 
inline ::Color * LoadPalette (int maxPaletteSize, int *colorsCount)
 Load colors palette from image as a Color array (RGBA - 32bit)
 
void LoadRaw (const std::string &fileName, int width, int height, int format, int headerSize)
 Load image from RAW file data.
 
inline ::Texture2D LoadTexture ()
 Load texture from image data.
 
Image & Mipmaps ()
 Generate all mipmap levels for a provided image.
 
 operator::Texture2D ()
 Load texture from image data.
 
Image & operator= (const ::Image &image)
 
Image & Resize (int newWidth, int newHeight)
 Resize and image to new size.
 
Image & ResizeCanvas (int newWidth, int newHeight, int offsetX, int offsetY, ::Color color={255, 255, 255, 255})
 Resize canvas and fill with color.
 
Image & ResizeNN (int newWidth, int newHeight)
 Resize and image to new size using Nearest-Neighbor scaling algorithm.
 
Image & RotateCCW ()
 Rotate image counter-clockwise 90deg.
 
Image & RotateCW ()
 Rotate image clockwise 90deg.
 
void SetData (void *value)
 Sets the data value for the object. More...
 
void SetFormat (int value)
 Sets the format value for the object. More...
 
void SetHeight (int value)
 Sets the height value for the object. More...
 
void SetMipmaps (int value)
 Sets the mipmaps value for the object. More...
 
void SetWidth (int value)
 Sets the width value for the object. More...
 
Image & ToPOT (::Color fillColor)
 Convert image to POT (power-of-two)
 
void Unload ()
 Unload image from CPU memory (RAM)
 
void UnloadColors (::Color *colors)
 Unload color data loaded with LoadImageColors()
 
void UnloadPalette (::Color *colors)
 Unload colors palette loaded with LoadImagePalette()
 

Static Public Member Functions

::Image Cellular (int width, int height, int tileSize)
 Generate image: cellular algorithm. More...
 
::Image Checked (int width, int height, int checksX, int checksY, ::Color col1={255, 255, 255, 255}, ::Color col2={0, 0, 0, 255})
 Generate image: checked.
 
::Image Color (int width, int height, ::Color color={255, 255, 255, 255})
 Generate image: plain color.
 
static int GetPixelDataSize (int width, int height, int format=PIXELFORMAT_UNCOMPRESSED_R32G32B32A32)
 Get pixel data size in bytes for certain format.
 
::Image GetScreenData ()
 Get pixel data from screen buffer and return an Image (screenshot)
 
::Image GradientH (int width, int height, ::Color left, ::Color right)
 Generate image: horizontal gradient.
 
::Image GradientRadial (int width, int height, float density, ::Color inner, ::Color outer)
 Generate image: radial gradient.
 
::Image GradientV (int width, int height, ::Color top, ::Color bottom)
 Generate image: vertical gradient.
 
::Image PerlinNoise (int width, int height, int offsetX, int offsetY, float scale=1.0f)
 Generate image: perlin noise.
 
::Image Text (const ::Font &font, const std::string &text, float fontSize, float spacing, ::Color tint={255, 255, 255, 255})
 
::Image Text (const std::string &text, int fontSize, ::Color color={255, 255, 255, 255})
 
::Image WhiteNoise (int width, int height, float factor)
 Generate image: white noise.
 

Detailed Description

Image type, bpp always RGBA (32bit)

Data stored in CPU memory (RAM)

Definition at line 15 of file Image.hpp.

Member Function Documentation

◆ Cellular()

::Image raylib::Image::Cellular ( int  width,
int  height,
int  tileSize 
)
inlinestatic

Generate image: cellular algorithm.

Bigger tileSize means bigger cells

Definition at line 122 of file Image.hpp.

◆ ColorBrightness()

Image& raylib::Image::ColorBrightness ( int  brightness)
inline

Modify image color: brightness.

Parameters
brightnessBrightness values between -255 and 255

Definition at line 399 of file Image.hpp.

◆ ColorContrast()

Image& raylib::Image::ColorContrast ( float  contrast)
inline

Modify image color: contrast.

Parameters
contrastContrast values between -100 and 100

Definition at line 389 of file Image.hpp.

◆ GetAlphaBorder()

Rectangle raylib::Image::GetAlphaBorder ( float  threshold) const
inline

Get image alpha border rectangle.

Parameters
thresholdThreshold is defined as a percentatge: 0.0f -> 1.0f

Definition at line 417 of file Image.hpp.

◆ GetData()

void* raylib::Image::GetData ( ) const
inline

Retrieves the data value for the object.

Returns
The data value of the object.

Definition at line 191 of file Image.hpp.

◆ GetFormat()

int raylib::Image::GetFormat ( ) const
inline

Retrieves the format value for the object.

Returns
The format value of the object.

Definition at line 195 of file Image.hpp.

◆ GetHeight()

int raylib::Image::GetHeight ( ) const
inline

Retrieves the height value for the object.

Returns
The height value of the object.

Definition at line 193 of file Image.hpp.

◆ GetMipmaps()

int raylib::Image::GetMipmaps ( ) const
inline

Retrieves the mipmaps value for the object.

Returns
The mipmaps value of the object.

Definition at line 194 of file Image.hpp.

◆ GetPixelDataSize()

int raylib::Image::GetPixelDataSize ( )
inline

Returns the pixel data size of the image.

Returns
The pixel data size of the image.

Definition at line 571 of file Image.hpp.

◆ GetWidth()

int raylib::Image::GetWidth ( ) const
inline

Retrieves the width value for the object.

Returns
The width value of the object.

Definition at line 192 of file Image.hpp.

◆ LoadFromMemory()

void raylib::Image::LoadFromMemory ( const std::string &  fileType,
const unsigned char *  fileData,
int  dataSize 
)
inline

Load image from memory buffer, fileType refers to extension: i.e.

"png".

Definition at line 159 of file Image.hpp.

References raylib::LoadImageFromMemory().

◆ SetData()

void raylib::Image::SetData ( void *  value)
inline

Sets the data value for the object.

Parameters
valueThe value of which to set data to.

Definition at line 191 of file Image.hpp.

◆ SetFormat()

void raylib::Image::SetFormat ( int  value)
inline

Sets the format value for the object.

Parameters
valueThe value of which to set format to.

Definition at line 195 of file Image.hpp.

◆ SetHeight()

void raylib::Image::SetHeight ( int  value)
inline

Sets the height value for the object.

Parameters
valueThe value of which to set height to.

Definition at line 193 of file Image.hpp.

◆ SetMipmaps()

void raylib::Image::SetMipmaps ( int  value)
inline

Sets the mipmaps value for the object.

Parameters
valueThe value of which to set mipmaps to.

Definition at line 194 of file Image.hpp.

◆ SetWidth()

void raylib::Image::SetWidth ( int  value)
inline

Sets the width value for the object.

Parameters
valueThe value of which to set width to.

Definition at line 192 of file Image.hpp.