Struct 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 Freeze for Image

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.