[][src]Struct sfml::graphics::Image

pub struct Image { /* fields omitted */ }

Loading, manipulating and saving images.

Methods

impl Image[src]

pub fn new(width: u32, height: u32) -> Self[src]

Create an image

This image is filled with black pixels.

Arguments

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

pub fn from_stream<T: Read + Seek>(stream: &mut T) -> Option<Self>[src]

Create an image from a stream.

This image is filled with black pixels.

Arguments

  • stream - Your struct, implementing Read and Seek

Return Some(Image) or None

pub fn from_memory(mem: &[u8]) -> Option<Self>[src]

Create an image from memory

This image is filled with black pixels.

Arguments

  • mem - Pointer to the file data in memory

Return Some(Image) or None

pub fn from_color(width: u32, height: u32, color: Color) -> Option<Self>[src]

Create an image and fill it with a unique color

Arguments

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

Return Some(Image) or None

pub fn from_file(filename: &str) -> Option<Self>[src]

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

Return Some(Image) or None

pub fn create_from_pixels(
    width: u32,
    height: u32,
    pixels: &[u8]
) -> Option<Self>
[src]

Create an image from an vector of pixels

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.

Arguments

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

Return Some(Image) or None

pub fn save_to_file(&self, filename: &str) -> bool[src]

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

pub fn size(&self) -> Vector2u[src]

Return the size of an image

Return the size in pixels

pub fn create_mask_from_color(&self, color: Color, alpha: u8)[src]

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

pub fn set_pixel(&mut self, x: u32, y: u32, color: Color)[src]

Change the color of a pixel in an image

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

Arguments

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

pub fn pixel_at(&self, x: u32, y: u32) -> Color[src]

Get the color of a pixel in an image

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

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)

pub fn pixel_data(&self) -> &[u8][src]

Return the memory buffer of this image.

pub fn flip_horizontally(&mut self)[src]

Flip an image horizontally (left <-> right)

pub fn flip_vertically(&mut self)[src]

Flip an image vertically (top <-> bottom)

pub fn copy_image(
    &mut self,
    source: &Image,
    dest_x: u32,
    dest_y: u32,
    source_rect: &IntRect,
    apply_alpha: bool
)
[src]

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

impl Drop for Image[src]

impl Clone for Image[src]

fn clone(&self) -> Self[src]

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

impl Debug for Image[src]

Auto Trait Implementations

impl !Send for Image

impl !Sync for Image

impl Unpin for Image

impl UnwindSafe for Image

impl RefUnwindSafe for Image

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]