Image


Object Hierarchy:

Object hierarchy for Image

Description:

[ Compact ]
[ Immutable ]
[ CCode ( cname = "sfImage" , copy_function = "sfImage_copy" , cprefix = "sfImage_" , free_function = "sfImage_destroy" ) ]
public class Image

Class for loading, manipulating and saving images.

sf.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.

sf.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 sf.Color. All the functions that return an array of pixels follow this rule, and all parameters that you pass to sf.Image functions (such as loadFromMemory) must use this representation as well.

A sf.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.

Usage example:

// Load an image file from a file
var background = new Image.FromFile("background.jpg");
if (background == null)
return -1;

// Create a 20x20 image filled with black color
var image = new Image.fromColor(20, 20, sf.Color.Black);

// Copy image1 on image2 at position (10, 10)
image.copy(background, 10, 10);

// Make the top-left pixel transparent
var color = image.getPixel(0, 0);
color.a = 0;
image.setPixel(0, 0, color);

// Save the image to a file
if (!image.saveToFile("result.png"))
return -1;

See also:

sf.Texture


Namespace: sf
Package: sfml

Content:

Creation methods:

Methods: