mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-19 09:48:15 +00:00
Add the SaveImageAs function
This commit is contained in:
@@ -835,7 +835,7 @@ RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Ve
|
|||||||
// Texture Loading and Drawing Functions (Module: textures)
|
// Texture Loading and Drawing Functions (Module: textures)
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Image/Texture2D data loading/unloading functions
|
// Image/Texture2D data loading/unloading/saving functions
|
||||||
RLAPI Image LoadImage(const char *fileName); // Load image from file into CPU memory (RAM)
|
RLAPI Image LoadImage(const char *fileName); // Load image from file into CPU memory (RAM)
|
||||||
RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image from Color array data (RGBA - 32bit)
|
RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image from Color array data (RGBA - 32bit)
|
||||||
RLAPI Image LoadImagePro(void *data, int width, int height, int format); // Load image from raw data with parameters
|
RLAPI Image LoadImagePro(void *data, int width, int height, int format); // Load image from raw data with parameters
|
||||||
@@ -849,6 +849,7 @@ RLAPI void UnloadRenderTexture(RenderTexture2D target);
|
|||||||
RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array
|
RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array
|
||||||
RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image
|
RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image
|
||||||
RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data
|
RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data
|
||||||
|
RLAPI void SaveImageAs(Image image, const char *fileName); // Save image to a PNG file
|
||||||
|
|
||||||
// Image manipulation functions
|
// Image manipulation functions
|
||||||
RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two)
|
RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two)
|
||||||
|
@@ -553,6 +553,18 @@ void UpdateTexture(Texture2D texture, const void *pixels)
|
|||||||
rlglUpdateTexture(texture.id, texture.width, texture.height, texture.format, pixels);
|
rlglUpdateTexture(texture.id, texture.width, texture.height, texture.format, pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save image to a PNG file
|
||||||
|
void SaveImageAs(Image image, const char *fileName)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
|
unsigned char* imgData = (unsigned char*)GetImageData(image); // this works since Color is just a container for the RGBA values
|
||||||
|
SavePNG(fileName, imgData, image.width, image.height, 4);
|
||||||
|
free(imgData);
|
||||||
|
|
||||||
|
TraceLog(INFO, "Image saved: %s", fileName);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Convert image data to desired format
|
// Convert image data to desired format
|
||||||
void ImageFormat(Image *image, int newFormat)
|
void ImageFormat(Image *image, int newFormat)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user