raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
Image.hpp
1#ifndef RAYLIB_CPP_INCLUDE_IMAGE_HPP_
2#define RAYLIB_CPP_INCLUDE_IMAGE_HPP_
3
4#include <span>
5#include <string>
6#include <string_view>
7
8#include "./Color.hpp"
9#include "./RaylibException.hpp"
10#include "./raylib-cpp-utils.hpp"
11#include "./raylib.hpp"
12
13namespace raylib {
19class Image : public ::Image {
20public:
21 Image(
22 void* data = nullptr,
23 int width = 0,
24 int height = 0,
25 int mipmaps = 1,
26 int format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
27 : ::Image{data, width, height, mipmaps, format} {
28 // Nothing.
29 }
30
31 Image(const ::Image& image) : ::Image(image) { }
32
40 Image(const std::string_view fileName) {
41 Load(fileName);
42 }
43
51 Image(const std::string_view fileName, int width, int height, int format, int headerSize = 0) {
52 Load(fileName, width, height, format, headerSize);
53 }
54
62 Image(const std::string_view fileName, int* frames) {
63 Load(fileName, frames);
64 }
65
73 Image(const std::string_view fileName, std::span<int> frames) {
74 Load(fileName, frames.data());
75 }
76
82 Image(const std::string_view fileType, const unsigned char* fileData, int dataSize) {
83 Load(fileType, fileData, dataSize);
84 }
85
91 Image(const ::Texture2D& texture) { Load(texture); }
92
93 Image(int width, int height, ::Color color = {255, 255, 255, 255}) { set(::GenImageColor(width, height, color)); }
94
95 Image(const std::string_view text, int fontSize, ::Color color = {255, 255, 255, 255}) {
96 set(::ImageText(text.data(), fontSize, color));
97 }
98
99 Image(const ::Font& font, const std::string_view text, float fontSize, float spacing,
100 ::Color tint = {255, 255, 255, 255}) {
101 set(::ImageTextEx(font, text.data(), fontSize, spacing, tint));
102 }
103
104 Image(const Image& other) { set(other.Copy()); }
105
106 Image(Image&& other) noexcept {
107 set(other);
108
109 other.data = nullptr;
110 other.width = 0;
111 other.height = 0;
112 other.mipmaps = 0;
113 other.format = 0;
114 }
115
116 static ::Image Text(const std::string_view text, int fontSize,
117 ::Color color = {255, 255, 255, 255}) {
118 return ::ImageText(text.data(), fontSize, color);
119 }
120
121 static ::Image Text(const ::Font& font, const std::string_view text, float fontSize, float spacing,
122 ::Color tint = {255, 255, 255, 255}) {
123 return ::ImageTextEx(font, text.data(), fontSize, spacing, tint);
124 }
125
129 static ::Image LoadFromScreen() { return ::LoadImageFromScreen(); }
130
134 static ::Image Color(int width, int height, ::Color color = {255, 255, 255, 255}) {
135 return ::GenImageColor(width, height, color);
136 }
137
141 static ::Image GradientLinear(int width, int height, int direction, ::Color start, ::Color end) {
142 return ::GenImageGradientLinear(width, height, direction, start, end);
143 }
144
148 static ::Image GradientRadial(int width, int height, float density, ::Color inner, ::Color outer) {
149 return ::GenImageGradientRadial(width, height, density, inner, outer);
150 }
151
155 static ::Image Checked(
156 int width,
157 int height,
158 int checksX,
159 int checksY,
160 ::Color col1 = {255, 255, 255, 255},
161 ::Color col2 = {0, 0, 0, 255}) {
162 return ::GenImageChecked(width, height, checksX, checksY, col1, col2);
163 }
164
168 static ::Image WhiteNoise(int width, int height, float factor) {
169 return ::GenImageWhiteNoise(width, height, factor);
170 }
171
175 static ::Image Cellular(int width, int height, int tileSize) { return ::GenImageCellular(width, height, tileSize); }
176
180 static ::Image GetClipboard() { return ::GetClipboardImage(); }
181
182 ~Image() { Unload(); }
183
184 Image& operator=(const ::Image& image) {
185 set(image);
186 return *this;
187 }
188
189 Image& operator=(const Image& other) {
190 if (this == &other) {
191 return *this;
192 }
193
194 Unload();
195 set(other.Copy());
196
197 return *this;
198 }
199
200 Image& operator=(Image&& other) noexcept {
201 if (this == &other) {
202 return *this;
203 }
204
205 Unload();
206 set(other);
207
208 other.data = nullptr;
209 other.width = 0;
210 other.height = 0;
211 other.mipmaps = 0;
212 other.format = 0;
213
214 return *this;
215 }
216
224 void Load(const std::string_view fileName) {
225 set(::LoadImage(fileName.data()));
226 if (!IsValid()) {
227 throw RaylibException("Failed to load Image from file: " + std::string(fileName));
228 }
229 }
230
238 void Load(const std::string_view fileName, int width, int height, int format, int headerSize) {
239 set(::LoadImageRaw(fileName.data(), width, height, format, headerSize));
240 if (!IsValid()) {
241 throw RaylibException("Failed to load Image from file: " + std::string(fileName));
242 }
243 }
244
252 void Load(const std::string_view fileName, int* frames) {
253 set(::LoadImageAnim(fileName.data(), frames));
254 if (!IsValid()) {
255 throw RaylibException("Failed to load Image from file: " + std::string(fileName));
256 }
257 }
258
266 void Load(const std::string_view fileName, std::span<int> frames) {
267 set(::LoadImageAnim(fileName.data(), frames.data()));
268 if (!IsValid()) {
269 throw RaylibException("Failed to load Image from file: " + std::string(fileName));
270 }
271 }
272
280 void Load(
281 const std::string_view fileType,
282 const unsigned char *fileData,
283 int dataSize) {
284 set(::LoadImageFromMemory(fileType.data(), fileData, dataSize));
285 if (!IsValid()) {
286 throw RaylibException("Failed to load Image data with file type: " + std::string(fileType));
287 }
288 }
289
297 void Load(
298 const std::string_view fileType,
299 const std::span<unsigned char> fileData) {
300 set(::LoadImageFromMemory(fileType.data(), fileData.data(), static_cast<int>(fileData.size())));
301 if (!IsValid()) {
302 throw RaylibException("Failed to load Image data with file type: " + std::string(fileType));
303 }
304 }
305
313 void Load(const ::Texture2D& texture) {
314 set(::LoadImageFromTexture(texture));
315 if (!IsValid()) {
316 throw RaylibException("Failed to load Image from texture.");
317 }
318 }
319
323 void Unload() {
324 if (data != nullptr) {
325 ::UnloadImage(*this);
326 data = nullptr;
327 }
328 }
329
335 void Export(const std::string_view fileName) const {
336 if (!::ExportImage(*this, fileName.data())) {
337 throw RaylibException(TextFormat("Failed to export Image to file: %s", fileName.data()));
338 }
339 }
340
344 unsigned char* ExportToMemory(const char* fileType, int* fileSize) {
345 return ::ExportImageToMemory(*this, fileType, fileSize);
346 }
347
348 unsigned char* ExportToMemory(const std::string_view fileType, std::span<int> fileSize) {
349 return ::ExportImageToMemory(*this, fileType.data(), fileSize.data());
350 }
351
357 void ExportAsCode(const std::string_view fileName) const {
358 if (!::ExportImageAsCode(*this, fileName.data())) {
359 throw RaylibException(TextFormat("Failed to export Image code to file: %s", fileName.data()));
360 }
361 }
362
363 GETTER(void*, Data, data)
364 GETTER(int, Width, width)
365 GETTER(int, Height, height)
366 GETTER(int, Mipmaps, mipmaps)
367 GETTER(int, Format, format)
368
374 void SetWidth(int width, int offsetX = 0, int offsetY = 0, ::Color fill = {255, 255, 255, 255}) {
375 ResizeCanvas(width, height, offsetX, offsetY, fill);
376 }
377
383 void SetHeight(int height, int offsetX = 0, int offsetY = 0, ::Color fill = {255, 255, 255, 255}) {
384 ResizeCanvas(width, height, offsetX, offsetY, fill);
385 }
386
390 [[nodiscard]] ::Vector2 GetSize() const { return {static_cast<float>(width), static_cast<float>(height)}; }
391
395 [[nodiscard]] ::Image Copy() const { return ::ImageCopy(*this); }
396
400 [[nodiscard]] ::Image FromImage(::Rectangle rec) const { return ::ImageFromImage(*this, rec); }
401
405 Image& Format(int newFormat) {
406 ::ImageFormat(this, newFormat);
407 return *this;
408 }
409
413 Image& ToPOT(::Color fillColor) {
414 ::ImageToPOT(this, fillColor);
415 return *this;
416 }
417
421 Image& Crop(::Rectangle crop) {
422 ::ImageCrop(this, crop);
423 return *this;
424 }
425
429 Image& AlphaCrop(float threshold) {
430 ::ImageAlphaCrop(this, threshold);
431 return *this;
432 }
433
437 Image& AlphaClear(::Color color, float threshold) {
438 ::ImageAlphaClear(this, color, threshold);
439 return *this;
440 }
441
445 Image& AlphaMask(const ::Image& alphaMask) {
446 ::ImageAlphaMask(this, alphaMask);
447 return *this;
448 }
449
454 ::ImageAlphaPremultiply(this);
455 return *this;
456 }
457
461 Image& Crop(int newWidth, int newHeight) { return Crop(0, 0, newWidth, newHeight); }
462
466 Image& Crop(::Vector2 size) { return Crop(0, 0, static_cast<int>(size.x), static_cast<int>(size.y)); }
467
471 Image& Crop(int offsetX, int offsetY, int newWidth, int newHeight) {
472 ::Rectangle rect{
473 static_cast<float>(offsetX),
474 static_cast<float>(offsetY),
475 static_cast<float>(newWidth),
476 static_cast<float>(newHeight)};
477 ::ImageCrop(this, rect);
478 return *this;
479 }
480
484 Image& Resize(int newWidth, int newHeight) {
485 ::ImageResize(this, newWidth, newHeight);
486 return *this;
487 }
488
492 Image& ResizeNN(int newWidth, int newHeight) {
493 ::ImageResizeNN(this, newWidth, newHeight);
494 return *this;
495 }
496
500 Image&
501 ResizeCanvas(int newWidth, int newHeight, int offsetX = 0, int offsetY = 0, ::Color color = {255, 255, 255, 255}) {
502 ::ImageResizeCanvas(this, newWidth, newHeight, offsetX, offsetY, color);
503 return *this;
504 }
505
510 ::ImageMipmaps(this);
511 return *this;
512 }
513
517 Image& Dither(int rBpp, int gBpp, int bBpp, int aBpp) {
518 ::ImageDither(this, rBpp, gBpp, bBpp, aBpp);
519 return *this;
520 }
521
526 ::ImageFlipVertical(this);
527 return *this;
528 }
529
534 ::ImageFlipHorizontal(this);
535 return *this;
536 }
537
543 Image& Rotate(Degree degrees) {
544 ::ImageRotate(this, static_cast<int>(degrees));
545 return *this;
546 }
547
552 ::ImageRotateCW(this);
553 return *this;
554 }
555
560 ::ImageRotateCCW(this);
561 return *this;
562 }
563
567 Image& ColorTint(::Color color = {255, 255, 255, 255}) {
568 ::ImageColorTint(this, color);
569 return *this;
570 }
571
576 ::ImageColorInvert(this);
577 return *this;
578 }
579
584 ::ImageColorGrayscale(this);
585 return *this;
586 }
587
593 Image& ColorContrast(float contrast) {
594 ::ImageColorContrast(this, contrast);
595 return *this;
596 }
597
603 Image& ColorBrightness(int brightness) {
604 ::ImageColorBrightness(this, brightness);
605 return *this;
606 }
607
611 Image& ColorReplace(::Color color, ::Color replace) {
612 ::ImageColorReplace(this, color, replace);
613 return *this;
614 }
615
621 [[nodiscard]] Rectangle GetAlphaBorder(float threshold) const { return ::GetImageAlphaBorder(*this, threshold); }
622
626 [[nodiscard]] raylib::Color GetColor(int x = 0, int y = 0) const { return ::GetImageColor(*this, x, y); }
627
631 [[nodiscard]] raylib::Color GetColor(::Vector2 position) const {
632 return ::GetImageColor(*this, static_cast<int>(position.x), static_cast<int>(position.y));
633 }
634
638 Image& ClearBackground(::Color color = {0, 0, 0, 255}) {
639 ::ImageClearBackground(this, color);
640 return *this;
641 }
642
646 void DrawPixel(int posX, int posY, ::Color color = {255, 255, 255, 255}) {
647 ::ImageDrawPixel(this, posX, posY, color);
648 }
649
650 void DrawPixel(::Vector2 position, ::Color color = {255, 255, 255, 255}) {
651 ::ImageDrawPixelV(this, position, color);
652 }
653
654 void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, ::Color color = {255, 255, 255, 255}) {
655 ::ImageDrawLine(this, startPosX, startPosY, endPosX, endPosY, color);
656 }
657
658 void DrawLine(::Vector2 start, ::Vector2 end, ::Color color = {255, 255, 255, 255}) {
659 ::ImageDrawLineV(this, start, end, color);
660 }
661
665 void DrawLine(::Vector2 start, ::Vector2 end, int thick, ::Color color = {255, 255, 255, 255}) {
666 ImageDrawLineEx(this, start, end, thick, color);
667 }
668
669 void DrawCircle(int centerX, int centerY, int radius, ::Color color = {255, 255, 255, 255}) {
670 ::ImageDrawCircle(this, centerX, centerY, radius, color);
671 }
672
673 void DrawCircle(::Vector2 center, int radius, ::Color color = {255, 255, 255, 255}) {
674 ::ImageDrawCircleV(this, center, radius, color);
675 }
676
677 void DrawRectangle(int posX, int posY, int width, int height, ::Color color = {255, 255, 255, 255}) {
678 ::ImageDrawRectangle(this, posX, posY, width, height, color);
679 }
680
681 void DrawRectangle(Vector2 position, Vector2 size, ::Color color = {255, 255, 255, 255}) {
682 ::ImageDrawRectangleV(this, position, size, color);
683 }
684
685 void DrawRectangle(::Rectangle rec, ::Color color = {255, 255, 255, 255}) {
686 ::ImageDrawRectangleRec(this, rec, color);
687 }
688
689 void DrawRectangleLines(::Rectangle rec, int thick = 1, ::Color color = {255, 255, 255, 255}) {
690 ::ImageDrawRectangleLines(this, rec, thick, color);
691 }
692
693 // TODO: Add ImageDrawTriangle()
694
695 void Draw(const ::Image& src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint = {255, 255, 255, 255}) {
696 ::ImageDraw(this, src, srcRec, dstRec, tint);
697 }
698
699 void DrawText(const char* text, ::Vector2 position, int fontSize, ::Color color = {255, 255, 255, 255}) {
700 ::ImageDrawText(this, text, static_cast<int>(position.x), static_cast<int>(position.y), fontSize, color);
701 }
702
703 void DrawText(const std::string_view text, ::Vector2 position, int fontSize,
704 ::Color color = {255, 255, 255, 255}) {
705 ::ImageDrawText(this,
706 text.data(),
707 static_cast<int>(position.x),
708 static_cast<int>(position.y),
709 fontSize,
710 color);
711 }
712
713 void DrawText(const std::string_view text, int x, int y, int fontSize,
714 ::Color color = {255, 255, 255, 255}) {
715 ::ImageDrawText(this, text.data(), x, y, fontSize, color);
716 }
717
718 void DrawText(const char* text, int x, int y, int fontSize, ::Color color = {255, 255, 255, 255}) {
719 ::ImageDrawText(this, text, x, y, fontSize, color);
720 }
721
722 void DrawText(const ::Font& font, const std::string_view text, ::Vector2 position,
723 float fontSize, float spacing, ::Color tint = {255, 255, 255, 255}) {
724 ::ImageDrawTextEx(this, font, text.data(), position, fontSize, spacing, tint);
725 }
726
727 void DrawText(
728 const ::Font& font,
729 const char* text,
730 ::Vector2 position,
731 float fontSize,
732 float spacing,
733 ::Color tint = {255, 255, 255, 255}) {
734 ::ImageDrawTextEx(this, font, text, position, fontSize, spacing, tint);
735 }
736
740 [[nodiscard]] ::Color* LoadColors() const { return ::LoadImageColors(*this); }
741
745 ::Color* LoadPalette(int maxPaletteSize, int* colorsCount) const {
746 return ::LoadImagePalette(*this, maxPaletteSize, colorsCount);
747 }
748
752 void UnloadColors(::Color* colors) const { ::UnloadImageColors(colors); }
753
757 void UnloadPalette(::Color* colors) const { ::UnloadImagePalette(colors); }
758
762 [[nodiscard]] ::Texture2D LoadTexture() const { return ::LoadTextureFromImage(*this); }
763
769 operator ::Texture2D() const { return LoadTexture(); }
770
774 static int GetPixelDataSize(int width, int height, int format = PIXELFORMAT_UNCOMPRESSED_R32G32B32A32) {
775 return ::GetPixelDataSize(width, height, format);
776 }
777
783 [[nodiscard]] int GetPixelDataSize() const { return ::GetPixelDataSize(width, height, format); }
784
790 [[nodiscard]] bool IsValid() const { return ::IsImageValid(*this); }
791
795 ::Image Channel(int selectedChannel) { return ::ImageFromChannel(*this, selectedChannel); }
796
800 void KernelConvolution(const float* kernel, int kernelSize) {
801 ::ImageKernelConvolution(this, kernel, kernelSize);
802 }
803protected:
804 void set(const ::Image& image) {
805 data = image.data;
806 width = image.width;
807 height = image.height;
808 mipmaps = image.mipmaps;
809 format = image.format;
810 }
811};
812} // namespace raylib
813
814using RImage = raylib::Image;
815
816#endif // RAYLIB_CPP_INCLUDE_IMAGE_HPP_
Color type, RGBA (32bit)
Definition: Color.hpp:16
Degree type (allows automatic worry free conversion between radians and degrees)
Image type, bpp always RGBA (32bit)
Definition: Image.hpp:19
void Load(const std::string_view fileName, int width, int height, int format, int headerSize)
Load image from RAW file data.
Definition: Image.hpp:238
void Load(const std::string_view fileType, const std::span< unsigned char > fileData)
Load image from memory buffer, fileType refers to extension: i.e.
Definition: Image.hpp:297
Image(const std::string_view fileName, int *frames)
Load an animation image from the given file.
Definition: Image.hpp:62
Image & ColorContrast(float contrast)
Modify image color: contrast.
Definition: Image.hpp:593
Image & Dither(int rBpp, int gBpp, int bBpp, int aBpp)
Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
Definition: Image.hpp:517
::Image WhiteNoise(int width, int height, float factor)
Generate image: white noise.
Definition: Image.hpp:168
Image & ColorTint(::Color color={255, 255, 255, 255})
Modify image color: tint.
Definition: Image.hpp:567
Image & ResizeNN(int newWidth, int newHeight)
Resize and image to new size using Nearest-Neighbor scaling algorithm.
Definition: Image.hpp:492
Image & Rotate(Degree degrees)
Rotate image by input angle in degrees (-359 to 359)
Definition: Image.hpp:543
Image & ResizeCanvas(int newWidth, int newHeight, int offsetX=0, int offsetY=0, ::Color color={255, 255, 255, 255})
Resize canvas and fill with color.
Definition: Image.hpp:501
::Color * LoadColors() const
Load color data from image as a Color array (RGBA - 32bit)
Definition: Image.hpp:740
::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.
Definition: Image.hpp:155
void Load(const ::Texture2D &texture)
Load an image from the given file.
Definition: Image.hpp:313
::Image Cellular(int width, int height, int tileSize)
Generate image: cellular algorithm.
Definition: Image.hpp:175
Image(const ::Texture2D &texture)
Load an image from the given file.
Definition: Image.hpp:91
Rectangle GetAlphaBorder(float threshold) const
Get image alpha border rectangle.
Definition: Image.hpp:621
::Image FromImage(::Rectangle rec) const
Create an image from another image piece.
Definition: Image.hpp:400
int GetPixelDataSize() const
Returns the pixel data size based on the current image.
Definition: Image.hpp:783
Image(const std::string_view fileName, std::span< int > frames)
Load an animation image from the given file.
Definition: Image.hpp:73
void KernelConvolution(const float *kernel, int kernelSize)
Apply custom square convolution kernel to image.
Definition: Image.hpp:800
Image(const std::string_view fileName)
Load an image from the given file.
Definition: Image.hpp:40
void Load(const std::string_view fileType, const unsigned char *fileData, int dataSize)
Load image from memory buffer, fileType refers to extension: i.e.
Definition: Image.hpp:280
raylib::Color GetColor(::Vector2 position) const
Get image pixel color at vector position.
Definition: Image.hpp:631
void SetHeight(int height, int offsetX=0, int offsetY=0, ::Color fill={255, 255, 255, 255})
Set the height of the image canvas.
Definition: Image.hpp:383
::Texture2D LoadTexture() const
Load texture from image data.
Definition: Image.hpp:762
Image & ColorGrayscale()
Modify image color: grayscale.
Definition: Image.hpp:583
void ExportAsCode(const std::string_view fileName) const
Export image as code file defining an array of bytes, returns true on success.
Definition: Image.hpp:357
void DrawLine(::Vector2 start, ::Vector2 end, int thick, ::Color color={255, 255, 255, 255})
Description: Draw a line defining thickness within an image.
Definition: Image.hpp:665
::Color * LoadPalette(int maxPaletteSize, int *colorsCount) const
Load colors palette from image as a Color array (RGBA - 32bit)
Definition: Image.hpp:745
Image & ColorBrightness(int brightness)
Modify image color: brightness.
Definition: Image.hpp:603
Image & RotateCW()
Rotate image clockwise 90deg.
Definition: Image.hpp:551
Image & FlipHorizontal()
Flip image horizontally.
Definition: Image.hpp:533
Image & AlphaPremultiply()
Premultiply alpha channel.
Definition: Image.hpp:453
Image & ToPOT(::Color fillColor)
Convert image to POT (power-of-two)
Definition: Image.hpp:413
Image & ClearBackground(::Color color={0, 0, 0, 255})
Clear image background with given color.
Definition: Image.hpp:638
Image & Crop(int offsetX, int offsetY, int newWidth, int newHeight)
Crop an image to area defined by a rectangle.
Definition: Image.hpp:471
bool IsValid() const
Retrieve whether or not the Image has been loaded.
Definition: Image.hpp:790
void Load(const std::string_view fileName, int *frames)
Load image sequence from file (frames appended to image.data).
Definition: Image.hpp:252
::Image Color(int width, int height, ::Color color={255, 255, 255, 255})
Generate image: plain color.
Definition: Image.hpp:134
Image & FlipVertical()
Flip image vertically.
Definition: Image.hpp:525
Image & RotateCCW()
Rotate image counter-clockwise 90deg.
Definition: Image.hpp:559
void Load(const std::string_view fileName)
Load image from file into CPU memory (RAM)
Definition: Image.hpp:224
::Image Copy() const
Create an image duplicate (useful for transformations)
Definition: Image.hpp:395
raylib::Color GetColor(int x=0, int y=0) const
Get image pixel color at (x, y) position.
Definition: Image.hpp:626
Image & Format(int newFormat)
Convert image data to desired format.
Definition: Image.hpp:405
Image & AlphaCrop(float threshold)
Crop image depending on alpha value.
Definition: Image.hpp:429
::Vector2 GetSize() const
Retrieve the width and height of the image.
Definition: Image.hpp:390
operator::Texture2D() const
Loads a texture from the image data.
Definition: Image.hpp:769
static int GetPixelDataSize(int width, int height, int format=PIXELFORMAT_UNCOMPRESSED_R32G32B32A32)
Get pixel data size in bytes for certain format.
Definition: Image.hpp:774
unsigned char * ExportToMemory(const char *fileType, int *fileSize)
Export image to memory buffer.
Definition: Image.hpp:344
Image(const std::string_view 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.
Definition: Image.hpp:51
::Image GradientRadial(int width, int height, float density, ::Color inner, ::Color outer)
Generate image: radial gradient.
Definition: Image.hpp:148
Image & Mipmaps()
Generate all mipmap levels for a provided image.
Definition: Image.hpp:509
Image & AlphaMask(const ::Image &alphaMask)
Apply alpha mask to image.
Definition: Image.hpp:445
::Image LoadFromScreen()
Get pixel data from screen buffer and return an Image (screenshot)
Definition: Image.hpp:129
Image & ColorInvert()
Modify image color: invert.
Definition: Image.hpp:575
void Unload()
Unload image from CPU memory (RAM)
Definition: Image.hpp:323
Image & Crop(int newWidth, int newHeight)
Crop an image to a new given width and height.
Definition: Image.hpp:461
Image(const std::string_view fileType, const unsigned char *fileData, int dataSize)
Load an image from the given file.
Definition: Image.hpp:82
void Export(const std::string_view fileName) const
Export image data to file, returns true on success.
Definition: Image.hpp:335
void UnloadColors(::Color *colors) const
Unload color data loaded with LoadImageColors()
Definition: Image.hpp:752
::Image Channel(int selectedChannel)
Create an image from a selected channel of another image (GRAYSCALE)
Definition: Image.hpp:795
void SetWidth(int width, int offsetX=0, int offsetY=0, ::Color fill={255, 255, 255, 255})
Set the width of the image canvas.
Definition: Image.hpp:374
::Image GradientLinear(int width, int height, int direction, ::Color start, ::Color end)
Generate image: linear gradient.
Definition: Image.hpp:141
Image & ColorReplace(::Color color, ::Color replace)
Modify image color: replace color.
Definition: Image.hpp:611
Image & AlphaClear(::Color color, float threshold)
Clear alpha channel to desired color.
Definition: Image.hpp:437
Image & Crop(::Rectangle crop)
Crop an image to area defined by a rectangle.
Definition: Image.hpp:421
void DrawPixel(int posX, int posY, ::Color color={255, 255, 255, 255})
Draw pixel within an image.
Definition: Image.hpp:646
::Image GetClipboard()
Get clipboard image content.
Definition: Image.hpp:180
void UnloadPalette(::Color *colors) const
Unload colors palette loaded with LoadImagePalette()
Definition: Image.hpp:757
Image & Resize(int newWidth, int newHeight)
Resize and image to new size.
Definition: Image.hpp:484
Image & Crop(::Vector2 size)
Crop an image to a new given width and height based on a vector.
Definition: Image.hpp:466
void Load(const std::string_view fileName, std::span< int > frames)
Load image sequence from file (frames appended to image.data).
Definition: Image.hpp:266
Exception used for most raylib-related exceptions.
Rectangle type.
Definition: Rectangle.hpp:12
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8
static inline ::Image LoadImage(const std::string_view fileName)
Load an image.
Definition: Functions.hpp:200
static inline ::Image LoadImageFromMemory(const std::string_view fileType, const unsigned char *fileData, int dataSize)
Load image from memory buffer, fileType refers to extension like "png".
Definition: Functions.hpp:230
static bool ExportImageAsCode(const Image &image, const std::string_view fileName)
Export image as code file (.h) defining an array of bytes.
Definition: Functions.hpp:246
static inline ::Image LoadImageAnim(const std::string_view fileName, int *frames)
Load animated image data.
Definition: Functions.hpp:216
static inline ::Image LoadImageRaw(const std::string_view fileName, int width, int height, int format, int headerSize)
Load an image from RAW file data.
Definition: Functions.hpp:207
static bool ExportImage(const Image &image, const std::string_view fileName)
Export image data to file.
Definition: Functions.hpp:239