summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2017-06-28 15:58:05 +0200
committerGitHub <[email protected]>2017-06-28 15:58:05 +0200
commitc51f63f6618d1e5bf1b8289a79e999b2e5337c6a (patch)
tree154088ba6c524ace47e89257ce8e29205553a7f2 /src
parent92ca68aac8e593b3df15a18ba86f8af0acff8921 (diff)
parent3fe268d004c9b95f9853b0d399887cae185a11d4 (diff)
downloadraylib-c51f63f6618d1e5bf1b8289a79e999b2e5337c6a.tar.gz
raylib-c51f63f6618d1e5bf1b8289a79e999b2e5337c6a.zip
Merge pull request #310 from nounoursheureux/save_image
Add the SaveImageAs function
Diffstat (limited to 'src')
-rw-r--r--src/raylib.h3
-rw-r--r--src/textures.c12
2 files changed, 14 insertions, 1 deletions
diff --git a/src/raylib.h b/src/raylib.h
index 29cc5728..aa55b776 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -835,7 +835,7 @@ RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Ve
// 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 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
@@ -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 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 SaveImageAs(const char *fileName, Image image); // Save image to a PNG file
// Image manipulation functions
RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two)
diff --git a/src/textures.c b/src/textures.c
index 99392516..34c7453a 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -553,6 +553,18 @@ void UpdateTexture(Texture2D texture, const void *pixels)
rlglUpdateTexture(texture.id, texture.width, texture.height, texture.format, pixels);
}
+// Save image to a PNG file
+void SaveImageAs(const char* fileName, Image image)
+{
+#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
void ImageFormat(Image *image, int newFormat)
{