Skip to main content

Image

Struct Image 

Source
pub struct Image(/* private fields */);

Implementations§

Source§

impl Image

Source

pub unsafe fn unwrap(self) -> Image

Take the raw ffi type. Must manually free memory by calling the proper unload function

Source§

impl Image

Source

pub fn to_raw(self) -> Image

returns the unwrapped raylib-sys object

Source

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

converts raylib-sys object to a “safe” version. Make sure to call this function from the thread the resource was created.

Source§

impl Image

Source

pub fn width(&self) -> i32

Source

pub fn height(&self) -> i32

Source

pub fn mipmaps(&self) -> i32

Source

pub unsafe fn data(&self) -> *mut c_void

Source

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

Apply Gaussian blur using a box blur approximation

Source

pub fn rotate(&mut self, degrees: i32)

Rotate image by input angle in degrees (-359 to 359)

Source

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

Get image pixel color at (x, y) position

Source

pub fn draw_circle_lines( &mut self, center_x: i32, center_y: i32, radius: i32, color: Color, )

Draw circle outline within an image

Source

pub fn draw_circle_lines_v( &mut self, center: Vector2, center_y: i32, color: Color, )

Draw circle outline within an image (Vector version)

Source

pub fn format(&self) -> PixelFormat

Source

pub fn from_image(&self, rec: impl Into<Rectangle>) -> Image

Source

pub fn from_channel(&self, selected_channel: i32) -> Image

Source

pub fn export_image(&self, filename: &str)

Exports image as a PNG file.

Source

pub fn export_image_as_code(&self, filename: &str)

Exports image as a PNG file.

Source

pub fn get_pixel_data_size(&self) -> usize

Get pixel data size in bytes (image or texture)

Source

pub fn get_image_data(&self) -> ImageColors

Gets pixel data from image as a Vec of Color structs.

Source

pub fn extract_palette(&self, max_palette_size: u32) -> ImagePalette

Extract color palette from image to maximum size

Source

pub fn to_pot(&mut self, fill_color: impl Into<Color>)

Converts image to POT (power-of-two).

Source

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

Converts image data to desired pixel format.

Source

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

Applies alpha mask to image. Alpha mask must be same size as the image. If alpha mask is not greyscale Ensure the colors are white (255, 255, 255, 255) or black (0, 0, 0, 0)

Source

pub fn alpha_clear(&mut self, color: impl Into<Color>, threshold: f32)

Clears alpha channel on image to desired color.

Source

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

Crops image depending on alpha value.

Source

pub fn alpha_premultiply(&mut self)

Premultiplies alpha channel on image.

Source

pub fn crop(&mut self, crop: impl Into<Rectangle>)

Crops image to a defined rectangle.

Source

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

Resizes image (bilinear filtering).

Source

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

Resizes image (nearest-neighbor scaling).

Source

pub fn resize_canvas( &mut self, new_width: i32, new_height: i32, offset_x: i32, offset_y: i32, color: impl Into<Color>, )

Resizes image canvas and fills with color.

Source

pub fn gen_mipmaps(&mut self)

Generates all mipmap levels for a provided image.

Source

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

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

Source

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

Get image alpha border rectangle

Source

pub fn clear_background(&mut self, color: impl Into<Color>)

Clear image background with given color

Source

pub fn draw( &mut self, src: &Image, src_rec: Rectangle, dst_rec: Rectangle, tint: impl Into<Color>, )

Draws a source image within a destination image.

Source

pub fn draw_pixel(&mut self, pos_x: i32, pos_y: i32, color: impl Into<Color>)

Draw pixel within an image

Source

pub fn draw_pixel_v( &mut self, position: impl Into<Vector2>, color: impl Into<Color>, )

Draw pixel within an image (Vector version)

Source

pub fn draw_line( &mut self, start_pos_x: i32, start_pos_y: i32, end_pos_x: i32, end_pos_y: i32, color: impl Into<Color>, )

Draw line within an image

Source

pub fn draw_line_ex( &mut self, start_pos: impl Into<Vector2>, end_pos: impl Into<Vector2>, thick: i32, color: impl Into<Color>, )

Draw a line (using triangles/quads)

Source

pub fn draw_line_v( &mut self, start: impl Into<Vector2>, end: impl Into<Vector2>, color: impl Into<Color>, )

Draw line within an image (Vector version)

Source

pub fn draw_triangle( &mut self, v1: impl Into<Vector2>, v2: impl Into<Vector2>, v3: impl Into<Vector2>, color: impl Into<Color>, )

Draw triangle within an image

Source

pub fn draw_triangle_ex( &mut self, v1: impl Into<Vector2>, v2: impl Into<Vector2>, v3: impl Into<Vector2>, c1: impl Into<Color>, c2: impl Into<Color>, c3: impl Into<Color>, )

Draw triangle with interpolated colors within an image

Source

pub fn draw_triangle_lines( &mut self, v1: impl Into<Vector2>, v2: impl Into<Vector2>, v3: impl Into<Vector2>, color: impl Into<Color>, )

Draw triangle outline within an image

Source

pub fn draw_triangle_fan( &mut self, points: Vec<Vector2>, color: impl Into<Color>, )

Draw a triangle fan defined by points within an image (first vertex is the center)

Source

pub fn draw_triangle_strip( &mut self, points: Vec<Vector2>, color: impl Into<Color>, )

Draw a triangle strip defined by points within an image

Source

pub fn draw_circle( &mut self, center_x: i32, center_y: i32, radius: i32, color: impl Into<Color>, )

Draw circle within an image

Source

pub fn draw_circle_v( &mut self, center: impl Into<Vector2>, radius: i32, color: impl Into<Color>, )

Draw circle within an image (Vector version)

Source

pub fn draw_rectangle( &mut self, pos_x: i32, pos_y: i32, width: i32, height: i32, color: impl Into<Color>, )

Draws a rectangle within an image.

Source

pub fn draw_rectangle_v( &mut self, position: impl Into<Vector2>, size: impl Into<Vector2>, color: impl Into<Color>, )

Draw rectangle within an image (Vector version)

Source

pub fn draw_rectangle_rec( &mut self, rectangle: impl Into<Rectangle>, color: impl Into<Color>, )

Draw rectangle within an image (Rectangle version)

Source

pub fn draw_rectangle_lines( &mut self, rec: Rectangle, thickness: i32, color: impl Into<Color>, )

Draws a rectangle within an image.

Source

pub fn draw_text( &mut self, text: &str, pos_x: i32, pos_y: i32, font_size: i32, color: impl Into<Color>, )

Draws text (default font) within an image (destination).

Source

pub fn draw_text_ex( &mut self, font: impl AsRef<Font>, text: &str, position: impl Into<Vector2>, font_size: f32, spacing: f32, color: impl Into<Color>, )

Draws text (default font) within an image (destination).

Source

pub fn flip_vertical(&mut self)

Flips image vertically.

Source

pub fn flip_horizontal(&mut self)

Flips image horizontally.

Source

pub fn rotate_cw(&mut self)

Rotates image clockwise by 90 degrees (PI/2 radians).

Source

pub fn rotate_ccw(&mut self)

Rotates image counterclockwise by 90 degrees (PI/2 radians).

Source

pub fn color_tint(&mut self, color: impl Into<Color>)

Tints colors in image using specified color.

Source

pub fn color_invert(&mut self)

Inverts the colors in image.

Source

pub fn color_grayscale(&mut self)

Converts `image color to grayscale.

Source

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

Adjusts the contrast of image.

Source

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

Adjusts the brightness of image.

Source

pub fn color_replace( &mut self, color: impl Into<Color>, replace: impl Into<Color>, )

Searches image for all occurences of color and replaces them with replace color.

Source

pub fn export_image_to_memory(&self, file_type: &str) -> Result<&[u8], Error>

Export image to memory buffer.

Source

pub fn kernel_convolution(&mut self, kernel: &[f32]) -> Result<(), Error>

Apply custom square convolution kernel to image NOTE: The convolution kernel matrix is expected to be square

Source

pub fn gen_image_color( width: i32, height: i32, color: impl Into<Color>, ) -> Image

Generates a plain color Image.

Source

pub fn gen_image_perlin_noise( &self, width: i32, height: i32, offset_x: i32, offset_y: i32, scale: f32, ) -> Image

Generate image: perlin noise

Source

pub fn gen_image_gradient_radial( width: i32, height: i32, density: f32, inner: impl Into<Color>, outer: impl Into<Color>, ) -> Image

Generates an Image containing a radial gradient.

Source

pub fn gen_image_checked( width: i32, height: i32, checks_x: i32, checks_y: i32, col1: impl Into<Color>, col2: impl Into<Color>, ) -> Image

Generates an Image containing a checkerboard pattern.

Source

pub fn gen_image_gradient_linear( width: i32, height: i32, direction: i32, start: Color, end: Color, ) -> Image

Generate images an image linear gradient. direction in expected to be degrees [0..360]. 0 results in a vertical gradient

Source

pub fn gen_image_gradient_square( width: i32, height: i32, density: f32, start: Color, end: Color, ) -> Image

Generate images an image with a square gradient For best results, density should be `0.0..1.0``

Source

pub fn gen_image_text(width: i32, height: i32, text: &str) -> Image

Source

pub fn gen_image_white_noise(width: i32, height: i32, factor: f32) -> Image

Generates an Image containing white noise.

Source

pub fn gen_image_cellular(width: i32, height: i32, tile_size: i32) -> Image

Generates an Image using a cellular algorithm. Bigger tile_size means bigger cells.

Source

pub fn load_image(filename: &str) -> Result<Image, Error>

Loads image from file into CPU memory (RAM).

Source

pub fn load_image_from_mem(filetype: &str, bytes: &[u8]) -> Result<Image, Error>

Loads image from a given memory buffer The input data is expected to be in a supported file format such as png. Which formats are supported depend on the build flags used for the raylib (C) library.

Source

pub fn load_image_anim(filename: &str, frame_num: &mut i32) -> Image

Load image sequence from file, with the number of frames loaded saved to frame_num. Image.data buffer includes all frames. All frames returned are in RGBA format. Frames delay data is discarded

Source

pub fn load_image_anim_from_memory( filetype: &str, data: &[u8], frame_num: &mut i32, ) -> Image

Load image from memory buffer, with the number of frames loaded saved to frame_num. fileType refers to extension: i.e. “.png”. File extension must be provided in lower-case

Source

pub fn load_image_raw( filename: &str, width: i32, height: i32, format: i32, header_size: i32, ) -> Result<Image, Error>

Loads image from RAW file data.

Source

pub fn image_text(text: &str, font_size: i32, color: impl Into<Color>) -> Image

Creates an image from text (custom font).

Source

pub fn image_text_ex( font: impl AsRef<Font>, text: &str, font_size: f32, spacing: f32, tint: impl Into<Color>, ) -> Image

Creates an image from text (custom font).

Source

pub fn is_image_valid(&self) -> bool

Trait Implementations§

Source§

impl AsMut<Image> for Image

Source§

fn as_mut(&mut self) -> &mut Image

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Image> for Image

Source§

fn as_ref(&self) -> &Image

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Image

Source§

fn clone(&self) -> Image

Returns a duplicate 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<(), Error>

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

impl Deref for Image

Source§

type Target = Image

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<Image as Deref>::Target

Dereferences the value.
Source§

impl DerefMut for Image

Source§

fn deref_mut(&mut self) -> &mut <Image as Deref>::Target

Mutably dereferences the value.
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 UnsafeUnpin 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.