Struct rust_raylib::texture::Image

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

Image, pixel data stored in CPU memory (RAM)

Implementations§

source§

impl Image

source

pub fn width(&self) -> u32

Image base width

source

pub fn height(&self) -> u32

Image base height

source

pub fn mipmaps(&self) -> u32

Mipmap levels, 1 by default

source

pub fn format(&self) -> PixelFormat

Data format

source

pub fn from_file(file_name: &str) -> Option<Self>

Load image from file into CPU memory (RAM)

source

pub fn from_raw_file( file_name: &str, width: u32, height: u32, format: PixelFormat, header_size: u32 ) -> Option<Self>

Load image from RAW file data

source

pub fn from_file_anim(file_name: &str) -> Option<(Self, usize)>

Load image sequence from file (frames appended to image.data)

Returns the amount of frames in the image.

source

pub fn from_memory( file_data: &[u8], format: Option<ImageFormat> ) -> Option<Self>

Load image from memory buffer

If format is None, it will make an educated guess on the ImageFormat (not all formats are supported for guessing).

source

pub fn from_texture(texture: &Texture) -> Option<Self>

Load image from GPU texture data

source

pub fn from_screen(_raylib: &Raylib) -> Option<Self>

Load image from screen buffer and (screenshot)

source

pub fn export(&self, file_name: &str) -> bool

Export image data to file, returns true on success

source

pub fn export_as_code(&self, file_name: &str) -> bool

Export image as code file defining an array of bytes, returns true on success

source

pub fn generate_color(width: u32, height: u32, color: Color) -> Self

Generate image: plain color

source

pub fn generate_gradient_vertical( width: u32, height: u32, top: Color, bottom: Color ) -> Self

Generate image: vertical gradient

source

pub fn generate_gradient_horizontal( width: u32, height: u32, left: Color, right: Color ) -> Self

Generate image: horizontal gradient

source

pub fn generate_gradient_radial( width: u32, height: u32, density: f32, inner: Color, outer: Color ) -> Self

Generate image: radial gradient

source

pub fn generate_checked( width: u32, height: u32, checks_x: u32, checks_y: u32, color1: Color, color2: Color ) -> Self

Generate image: checked

source

pub fn generate_white_noise(width: u32, height: u32, factor: f32) -> Self

Generate image: white noise

source

pub fn generate_perlin_noise( width: u32, height: u32, offset_x: i32, offset_y: i32, scale: f32 ) -> Self

Generate image: perlin noise

source

pub fn generate_cellular(width: u32, height: u32, tile_size: u32) -> Self

Generate image: cellular algorithm, bigger tileSize means bigger cells

source

pub fn generate_text(width: u32, height: u32, text: &str) -> Self

Generate image: grayscale image from text data

source

pub fn from_other_image(image: Self, rect: Rectangle) -> Self

Create an image from another image piece

source

pub fn text(text: &str, font_size: u32, color: Color) -> Self

Create an image from text (default font)

source

pub fn text_with_font( text: &str, font: &Font, font_size: f32, spacing: f32, tint: Color ) -> Self

Create an image from text (custom sprite font)

source

pub fn convert_to_format(&mut self, new_format: PixelFormat)

Convert image data to desired format

source

pub fn convert_to_power_of_two(&mut self, fill: Color)

Convert image to POT (power-of-two)

source

pub fn crop(&mut self, rect: Rectangle)

Crop an image to a defined rectangle

source

pub fn alpha_crop(&mut self, threshold: f32)

Crop image depending on alpha value

source

pub fn alpha_clear(&mut self, color: Color, threshold: f32)

Clear alpha channel to desired color

source

pub fn alpha_mask(&mut self, alpha_mask: &Image)

Apply alpha mask to image

source

pub fn alpha_premultiply(&mut self)

Premultiply alpha channel

source

pub fn blur_gaussian(&mut self, blur_size: u32)

Apply Gaussian blur using a box blur approximation

source

pub fn resize(&mut self, new_width: u32, new_height: u32)

Resize image (Bicubic scaling algorithm)

source

pub fn resize_nn(&mut self, new_width: u32, new_height: u32)

Resize image (Nearest-Neighbor scaling algorithm)

source

pub fn resize_canvas( &mut self, new_width: u32, new_height: u32, offset_x: i32, offset_y: i32, fill: Color )

Resize canvas and fill with color

source

pub fn compute_mipmaps(&mut self)

Compute all mipmap levels for a provided image

source

pub fn dither(&mut self, r_bpp: u32, g_bpp: u32, b_bpp: u32, a_bpp: u32)

Dither image data to 16bpp or lower (Floyd-Steinberg dithering)

source

pub fn flip_vertical(&mut self)

Flip image vertically

source

pub fn flip_horizontal(&mut self)

Flip image horizontally

source

pub fn rotate_clockwise(&mut self)

Rotate image clockwise 90deg

source

pub fn rotate_counter_clockwise(&mut self)

Rotate image counter-clockwise 90deg

source

pub fn color_tint(&mut self, color: Color)

Modify image color: tint

source

pub fn color_invert(&mut self)

Modify image color: invert

source

pub fn color_grayscale(&mut self)

Modify image color: grayscale

source

pub fn color_contrast(&mut self, contrast: f32)

Modify image color: contrast (-100 to 100)

source

pub fn color_brightness(&mut self, brightness: i32)

Modify image color: brightness (-255 to 255)

source

pub fn color_replace(&mut self, color: Color, replace: Color)

Modify image color: replace color

source

pub fn load_colors(&self) -> Vec<Color>

Load color data from image as a Color array (RGBA - 32bit)

source

pub fn load_palette(&self, max_size: usize) -> Vec<Color>

Load colors palette from image as a Color array (RGBA - 32bit)

source

pub fn get_alpha_border(&self, threshold: f32) -> Rectangle

Get image alpha border rectangle

source

pub fn get_color(&self, x: u32, y: u32) -> Color

Get image pixel color at (x, y) position

source

pub fn clear_background(&mut self, color: Color)

Clear image background with given color

source

pub fn draw_pixel(&mut self, pos: Vector2, color: Color)

Draw pixel within an image

source

pub fn draw_line(&mut self, start: Vector2, end: Vector2, color: Color)

Draw line within an image

source

pub fn draw_circle(&mut self, center: Vector2, radius: u32, color: Color)

Draw a filled circle within an image

source

pub fn draw_circle_lines_v( &mut self, center: Vector2, radius: u32, color: Color )

Draw circle outline within an image

source

pub fn draw_rectangle(&mut self, rect: Rectangle, color: Color)

Draw rectangle within an image

source

pub fn draw_rectangle_lines( &mut self, rect: Rectangle, thickness: u32, color: Color )

Draw rectangle lines within an image

source

pub fn draw_image( &mut self, source: &Image, source_rect: Rectangle, dest_rect: Rectangle, tint: Color )

Draw a source image within a destination image (tint applied to source)

source

pub fn draw_text( &mut self, text: &str, position: Vector2, font_size: u32, color: Color )

Draw text (using default font) within an image (destination)

source

pub fn draw_text_with_font( &mut self, text: &str, pos: Vector2, font: &Font, font_size: f32, spacing: f32, tint: Color )

Draw text (custom sprite font) within an image (destination)

source

pub fn get_pixel_data_size(&self) -> usize

Get pixel data size in bytes for this image

source

pub fn rectangle(&self) -> Rectangle

Returns a rectangle with x = 0, y = 0; width and height correspond to image’s dimensions

source

pub fn as_raw(&self) -> &Image

Get the ‘raw’ ffi type Take caution when cloning so it doesn’t outlive the original

source

pub fn as_raw_mut(&mut self) -> &mut Image

Get the ‘raw’ ffi type Take caution when cloning so it doesn’t outlive the original

source

pub unsafe fn from_raw(raw: Image) -> Self

Convert a ‘raw’ ffi object to a safe wrapper

Safety
  • The raw object must be correctly initialized
  • The raw object should be unique. Otherwise, make sure its clones don’t outlive the newly created object.

Trait Implementations§

source§

impl Clone for Image

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Image

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Image

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Image

§

impl !Send for Image

§

impl !Sync for Image

§

impl Unpin for Image

§

impl UnwindSafe for Image

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.