Struct sfml::graphics::Image

source ·
pub struct Image { /* private fields */ }
Expand description

Loading, manipulating and saving images.

Implementations§

Create an image

This image is filled with black pixels.

Arguments
  • width - Width of the image
  • height - Height of the image

Create an image from a custom stream.

The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg. If this function fails, the image is left unchanged.

Arguments
  • stream - Your struct, implementing Read and Seek

Returns None if loading fails

Create an image from a file in memory

The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg. If this function fails, the image is left unchanged.

Arguments
  • mem - Pointer to the file data in memory

Returns None if loading fails.

Create an image and fill it with a unique color

Arguments
  • width - Width of the image
  • height - Height of the image
  • color - Fill color

Returns None if creation fails.

Create an image from a file on disk

The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg. If this function fails, the image is left unchanged.

Arguments
  • filename - Path of the image file to load

Returns None if loading fails

Create an image from an vector of pixels

Arguments
  • width - Width of the image
  • height - Height of the image
  • pixels - Vector of pixels to copy to the image

Returns None if creation fails.

Safety

The pixel vector is assumed to contain 32-bits RGBA pixels, and have the given width and height. If not, this is an undefined behaviour.

Save an image to a file on disk

The format of the image is automatically deduced from the extension. The supported image formats are bmp, png, tga and jpg. The destination file is overwritten if it already exists. This function fails if the image is empty.

Arguments
  • filename - Path of the file to save

Return true if saving was successful

Return the size of an image

Return the size in pixels

Create a transparency mask from a specified color-key

This function sets the alpha value of every pixel matching the given color to alpha (0 by default), so that they become transparent.

Arguments
  • color - Color to make transparent
  • alpha - Alpha value to assign to transparent pixels

Change the color of a pixel in an image

Arguments
  • x - X coordinate of pixel to change
  • y - Y coordinate of pixel to change
  • color - New color of the pixel
Safety

This function doesn’t check the validity of the pixel coordinates, using out-of-range values will result in an undefined behaviour.

Get the color of a pixel in an image

Arguments
  • x - X coordinate of pixel to get
  • y - Y coordinate of pixel to get

Return the Color of the pixel at coordinates (x, y)

Safety

This function doesn’t check the validity of the pixel coordinates, using out-of-range values will result in an undefined behaviour.

Return the memory buffer of this image.

Flip an image horizontally (left <-> right)

Flip an image vertically (top <-> bottom)

Copy pixels from an image onto another

This function does a slow pixel copy and should not be used intensively. It can be used to prepare a complex static image from several others, but if you need this kind of feature in real-time you’d better use RenderTexture.

If sourceRect is empty, the whole image is copied. If applyAlpha is set to true, the transparency of source pixels is applied. If it is false, the pixels are copied unchanged with their alpha value.

Arguments
  • source - Source image to copy
  • destX - X coordinate of the destination position
  • destY - Y coordinate of the destination position
  • sourceRect - Sub-rectangle of the source image to copy
  • applyAlpha - Should the copy take in account the source transparency?

Trait Implementations§

Return a new Image or panic! if there is not enough memory

Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.