raylib-cpp
C++ object-oriented wrapper library for raylib.
Public Member Functions | Static Public Member Functions | Protected 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)
 Load an image from the given file. More...
 
 Image (const Image &other)
 
 Image (const std::string &fileName)
 Load an image from the given file. More...
 
 Image (const std::string &fileName, int *frames)
 Load an animation image from the given file. More...
 
 Image (const std::string &fileName, int width, int height, int format, int headerSize=0)
 Load a raw image from the given file, with the provided width, height, and formats. More...
 
 Image (const std::string &fileType, const unsigned char *fileData, int dataSize)
 Load an image from the given file. More...
 
 Image (const std::string &text, int fontSize, ::Color color={255, 255, 255, 255})
 
 Image (Image &&other)
 
 Image (int width, int height, ::Color color={255, 255, 255, 255})
 
 Image (void *data=nullptr, int width=0, int height=0, int mipmaps=1, int format=PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
 
ImageAlphaClear (::Color color, float threshold)
 Clear alpha channel to desired color.
 
ImageAlphaCrop (float threshold)
 Crop image depending on alpha value.
 
ImageAlphaMask (const ::Image &alphaMask)
 Apply alpha mask to image.
 
ImageAlphaPremultiply ()
 Premultiply alpha channel.
 
::Image Channel (int selectedChannel)
 Create an image from a selected channel of another image (GRAYSCALE)
 
ImageClearBackground (::Color color={0, 0, 0, 255})
 Clear image background with given color.
 
ImageColorBrightness (int brightness)
 Modify image color: brightness. More...
 
ImageColorContrast (float contrast)
 Modify image color: contrast. More...
 
ImageColorGrayscale ()
 Modify image color: grayscale.
 
ImageColorInvert ()
 Modify image color: invert.
 
ImageColorReplace (::Color color, ::Color replace)
 Modify image color: replace color.
 
ImageColorTint (::Color color={255, 255, 255, 255})
 Modify image color: tint.
 
::Image Copy () const
 Create an image duplicate (useful for transformations)
 
ImageCrop (::Rectangle crop)
 Crop an image to area defined by a rectangle.
 
ImageCrop (::Vector2 size)
 Crop an image to a new given width and height based on a vector.
 
ImageCrop (int newWidth, int newHeight)
 Crop an image to a new given width and height.
 
ImageCrop (int offsetX, int offsetY, int newWidth, int newHeight)
 Crop an image to area defined by a rectangle.
 
ImageDither (int rBpp, int gBpp, int bBpp, int aBpp)
 Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
 
void Draw (const ::Image &src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint={255, 255, 255, 255})
 
void DrawCircle (::Vector2 center, int radius, ::Color color={255, 255, 255, 255})
 
void DrawCircle (int centerX, int centerY, int radius, ::Color color={255, 255, 255, 255})
 
void DrawLine (::Vector2 start, ::Vector2 end, ::Color color={255, 255, 255, 255})
 
void DrawLine (::Vector2 start, ::Vector2 end, int thick, ::Color color={255, 255, 255, 255})
 Description: Draw a line defining thickness within an image.
 
void DrawLine (int startPosX, int startPosY, int endPosX, int endPosY, ::Color color={255, 255, 255, 255})
 
void DrawPixel (::Vector2 position, ::Color color={255, 255, 255, 255})
 
void DrawPixel (int posX, int posY, ::Color color={255, 255, 255, 255})
 Draw pixel within an image.
 
void DrawRectangle (::Rectangle rec, ::Color color={255, 255, 255, 255})
 
void DrawRectangle (int posX, int posY, int width, int height, ::Color color={255, 255, 255, 255})
 
void DrawRectangle (Vector2 position, Vector2 size, ::Color color={255, 255, 255, 255})
 
void DrawRectangleLines (::Rectangle rec, int thick=1, ::Color color={255, 255, 255, 255})
 
void DrawText (const ::Font &font, const char *text, ::Vector2 position, float fontSize, float spacing, ::Color tint={255, 255, 255, 255})
 
void DrawText (const ::Font &font, const std::string &text, ::Vector2 position, float fontSize, float spacing, ::Color tint={255, 255, 255, 255})
 
void DrawText (const char *text, ::Vector2 position, int fontSize, ::Color color={255, 255, 255, 255})
 
void DrawText (const char *text, int x, int y, int fontSize, ::Color color={255, 255, 255, 255})
 
void DrawText (const std::string &text, ::Vector2 position, int fontSize, ::Color color={255, 255, 255, 255})
 
void DrawText (const std::string &text, int x, int y, int fontSize, ::Color color={255, 255, 255, 255})
 
void Export (const std::string &fileName) const
 Export image data to file, returns true on success. More...
 
void ExportAsCode (const std::string &fileName) const
 Export image as code file defining an array of bytes, returns true on success. More...
 
unsigned char * ExportToMemory (const char *fileType, int *fileSize)
 Export image to memory buffer.
 
ImageFlipHorizontal ()
 Flip image horizontally.
 
ImageFlipVertical ()
 Flip image vertically.
 
ImageFormat (int newFormat)
 Convert image data to desired format.
 
::Image FromImage (::Rectangle rec) const
 Create an image from another image piece.
 
Rectangle GetAlphaBorder (float threshold) const
 Get image alpha border rectangle. More...
 
raylib::Color GetColor (::Vector2 position) const
 Get image pixel color at vector position.
 
raylib::Color GetColor (int x=0, int y=0) const
 Get image pixel color at (x, y) position.
 
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 () const
 Returns the pixel data size based on the current image. More...
 
::Vector2 GetSize () const
 Retrieve the width and height of the image.
 
int GetWidth () const
 Retrieves the width value for the object. More...
 
bool IsValid () const
 Retrieve whether or not the Image has been loaded. More...
 
void KernelConvolution (const float *kernel, int kernelSize)
 Apply custom square convolution kernel to image.
 
void Load (const ::Texture2D &texture)
 Load an image from the given file. More...
 
void Load (const std::string &fileName)
 Load image from file into CPU memory (RAM) More...
 
void Load (const std::string &fileName, int *frames)
 Load image sequence from file (frames appended to image.data). More...
 
void Load (const std::string &fileName, int width, int height, int format, int headerSize)
 Load image from RAW file data. More...
 
void Load (const std::string &fileType, const unsigned char *fileData, int dataSize)
 Load image from memory buffer, fileType refers to extension: i.e. More...
 
::ColorLoadColors () const
 Load color data from image as a Color array (RGBA - 32bit)
 
::ColorLoadPalette (int maxPaletteSize, int *colorsCount) const
 Load colors palette from image as a Color array (RGBA - 32bit)
 
::Texture2D LoadTexture () const
 Load texture from image data.
 
ImageMipmaps ()
 Generate all mipmap levels for a provided image.
 
 operator::Texture2D ()
 Loads a texture from the image data. More...
 
Imageoperator= (const ::Image &image)
 
Imageoperator= (const Image &other)
 
Imageoperator= (Image &&other) noexcept
 
ImageResize (int newWidth, int newHeight)
 Resize and image to new size.
 
ImageResizeCanvas (int newWidth, int newHeight, int offsetX=0, int offsetY=0, ::Color color={255, 255, 255, 255})
 Resize canvas and fill with color.
 
ImageResizeNN (int newWidth, int newHeight)
 Resize and image to new size using Nearest-Neighbor scaling algorithm.
 
ImageRotate (int degrees)
 Rotate image by input angle in degrees (-359 to 359)
 
ImageRotateCCW ()
 Rotate image counter-clockwise 90deg.
 
ImageRotateCW ()
 Rotate image clockwise 90deg.
 
void SetHeight (int height, int offsetX=0, int offsetY=0, ::Color fill={255, 255, 255, 255})
 Set the height of the image canvas. More...
 
void SetWidth (int width, int offsetX=0, int offsetY=0, ::Color fill={255, 255, 255, 255})
 Set the width of the image canvas. More...
 
ImageToPOT (::Color fillColor)
 Convert image to POT (power-of-two)
 
void Unload ()
 Unload image from CPU memory (RAM)
 
void UnloadColors (::Color *colors) const
 Unload color data loaded with LoadImageColors()
 
void UnloadPalette (::Color *colors) const
 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.
 
::Image GetClipboard ()
 Get clipboard image content.
 
static int GetPixelDataSize (int width, int height, int format=PIXELFORMAT_UNCOMPRESSED_R32G32B32A32)
 Get pixel data size in bytes for certain format.
 
::Image GradientLinear (int width, int height, int direction, ::Color start, ::Color end)
 Generate image: linear gradient.
 
::Image GradientRadial (int width, int height, float density, ::Color inner, ::Color outer)
 Generate image: radial gradient.
 
::Image LoadFromScreen ()
 Get pixel data from screen buffer and return an Image (screenshot)
 
::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.
 

Protected Member Functions

void set (const ::Image &image)
 

Detailed Description

Image type, bpp always RGBA (32bit)

Data stored in CPU memory (RAM)

Definition at line 17 of file Image.hpp.

Constructor & Destructor Documentation

◆ Image() [1/5]

raylib::Image::Image ( const std::string &  fileName)
inline

Load an image from the given file.

Exceptions
raylib::RaylibExceptionThrown if the image failed to load from the file.
See also
Load()

Definition at line 38 of file Image.hpp.

References Load().

◆ Image() [2/5]

raylib::Image::Image ( const std::string &  fileName,
int  width,
int  height,
int  format,
int  headerSize = 0 
)
inline

Load a raw image from the given file, with the provided width, height, and formats.

Exceptions
raylib::RaylibExceptionThrown if the image failed to load from the file.
See also
LoadRaw()

Definition at line 47 of file Image.hpp.

References Load().

◆ Image() [3/5]

raylib::Image::Image ( const std::string &  fileName,
int *  frames 
)
inline

Load an animation image from the given file.

Exceptions
raylib::RaylibExceptionThrown if the image failed to load from the file.
See also
LoadAnim()

Definition at line 58 of file Image.hpp.

References Load().

◆ Image() [4/5]

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

Load an image from the given file.

Exceptions
raylib::RaylibExceptionThrown if the image failed to load from the file.

Definition at line 65 of file Image.hpp.

References Load().

◆ Image() [5/5]

raylib::Image::Image ( const ::Texture2D texture)
inline

Load an image from the given file.

Exceptions
raylib::RaylibExceptionThrown if the image failed to load from the file.

Definition at line 74 of file Image.hpp.

References Load().

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 165 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 554 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 544 of file Image.hpp.

◆ Export()

void raylib::Image::Export ( const std::string &  fileName) const
inline

Export image data to file, returns true on success.

Exceptions
raylib::RaylibExceptionThrown if the image failed to load from the file.

Definition at line 292 of file Image.hpp.

References raylib::ExportImage().

◆ ExportAsCode()

void raylib::Image::ExportAsCode ( const std::string &  fileName) const
inline

Export image as code file defining an array of bytes, returns true on success.

Exceptions
raylib::RaylibExceptionThrown if the image failed to load from the file.

Definition at line 310 of file Image.hpp.

References raylib::ExportImageAsCode().

◆ 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 572 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 316 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 320 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 318 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 319 of file Image.hpp.

◆ GetPixelDataSize()

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

Returns the pixel data size based on the current image.

Returns
The pixel data size of the image.

Definition at line 738 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 317 of file Image.hpp.

◆ IsValid()

bool raylib::Image::IsValid ( ) const
inline

Retrieve whether or not the Image has been loaded.

Returns
True or false depending on whether the Image has been loaded.

Definition at line 745 of file Image.hpp.

Referenced by Load().

◆ Load() [1/5]

void raylib::Image::Load ( const ::Texture2D texture)
inline

Load an image from the given file.

Exceptions
raylib::RaylibExceptionThrown if the image animation to load from the file.
See also
::LoadImageFromTexture()

Definition at line 270 of file Image.hpp.

References IsValid().

◆ Load() [2/5]

void raylib::Image::Load ( const std::string &  fileName)
inline

Load image from file into CPU memory (RAM)

Exceptions
raylib::RaylibExceptionThrown if the image failed to load from the file.
See also
LoadImage()

Definition at line 214 of file Image.hpp.

References IsValid(), and raylib::LoadImage().

Referenced by Image().

◆ Load() [3/5]

void raylib::Image::Load ( const std::string &  fileName,
int *  frames 
)
inline

Load image sequence from file (frames appended to image.data).

Exceptions
raylib::RaylibExceptionThrown if the image animation to load from the file.
See also
LoadImageAnim()

Definition at line 242 of file Image.hpp.

References IsValid(), and raylib::LoadImageAnim().

◆ Load() [4/5]

void raylib::Image::Load ( const std::string &  fileName,
int  width,
int  height,
int  format,
int  headerSize 
)
inline

Load image from RAW file data.

Exceptions
raylib::RaylibExceptionThrown if the image failed to load from the file.
See also
LoadImageRaw()

Definition at line 228 of file Image.hpp.

References IsValid(), and raylib::LoadImageRaw().

◆ Load() [5/5]

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

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

"png".

Exceptions
raylib::RaylibExceptionThrown if the image animation to load from the file.
See also
LoadImageFromMemory()

Definition at line 256 of file Image.hpp.

References IsValid(), and raylib::LoadImageFromMemory().

◆ operator::Texture2D()

raylib::Image::operator::Texture2D ( )
inline

Loads a texture from the image data.

See also
LoadTexture()

Definition at line 724 of file Image.hpp.

References LoadTexture().

◆ SetHeight()

void raylib::Image::SetHeight ( int  height,
int  offsetX = 0,
int  offsetY = 0,
::Color  fill = {255, 255, 255, 255} 
)
inline

Set the height of the image canvas.

See also
ResizeCanvas

Definition at line 336 of file Image.hpp.

◆ SetWidth()

void raylib::Image::SetWidth ( int  width,
int  offsetX = 0,
int  offsetY = 0,
::Color  fill = {255, 255, 255, 255} 
)
inline

Set the width of the image canvas.

See also
ResizeCanvas

Definition at line 327 of file Image.hpp.