dsfml.graphics.image

$(U Image) is an abstraction to manipulate images as bidimensional arrays of pixels. The class provides functions to load, read, write and save pixels, as well as many other useful functions.

$(U Image) can handle a unique internal representation of pixels, which is RGBA 32 bits. This means that a pixel must be composed of 8 bits red, green, blue and alpha channels – just like a $(COLOR_LINK). All the functions that return an array of pixels follow this rule, and all parameters that you pass to $(U Image) functions (such as loadFromPixels) must use this representation as well.

An $(U Image) can be copied, but it is a heavy resource and if possible you should always use const references to pass or return them to avoid useless copies.

Members

Classes

Image
class Image

Class for loading, manipulating and saving images.

Examples

1 // Load an image file from a file
2 auto background = new Image();
3 if (!background.loadFromFile("background.jpg"))
4    return -1;
5 
6 // Create a 20x20 image filled with black color
7 auto image = new Image();
8 image.create(20, 20, Color.Black);
9 
10 // Copy image1 on image2 at position (10, 10)
11 image.copy(background, 10, 10);
12 
13 // Make the top-left pixel transparent
14 auto color = image.getPixel(0, 0);
15 color.a = 0;
16 image.setPixel(0, 0, color);
17 
18 // Save the image to a file
19 if (!image.saveToFile("result.png"))
20    return -1;

See Also

$(TEXTURE_LINK)

Meta